Outside Interval
Programming Basics · C++
TASK
Problem
Integers `x`, `l`, and `r` are given. Print `YES` if `x` lies outside the inclusive interval `[l, r]`; otherwise print `NO`.
EXAMPLE
Example
0 1 5
YES
LIMITS
Constraints
All values are integers with magnitude at most 10^9.
LEARN
Theory for this problem
+
Logical AND `&&`, OR `||`, and negation `!` combine boolean conditions. Parentheses make the intended grouping explicit.
Connection to “Outside Interval”: here, intermediate values are best kept in named variables so the formula stays readable and data types remain clear.
NEED HELP?
Hints
+
['Translate the verbal condition into one boolean expression.', 'After solving “Outside Interval”, verify the algorithm on your own small example and on an allowed boundary case. Print only the required result with no extra text.']
ANSWER
Solution
+
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
long long x, l, r;
cin >> x >> l >> r;
cout << ((x < l || x > r) ? "YES" : "NO") << '\n';
return 0;
}