WTRMIXING - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: Kanhaiya Mohan
Testers: Takuki Kurokawa, Utkarsh Gupta
Editorialist: Nishank Suresh

DIFFICULTY:

694

PREREQUISITES:

None

PROBLEM:

Chef has X litres of hot water and Y litres of cold water. The current water temperature is A and he’d like it to be B. Can he achieve this?

EXPLANATION:

Since Chef has X litres of hot water and Y litres of cold water:

  • The maximum temperature Chef can attain is A+X
  • The minimum temperature Chef can attain is A-Y

Notice that any temperature between these two is also easily attainable since he can only move in steps of 1.
So, Y must lie in this range: that is, the answer is “Yes” if and only if A-Y \leq B \leq A+X.

TIME COMPLEXITY

\mathcal{O}(1) per test case.

CODE:

Editorialist's code (Python)
for _ in range(int(input())):
    a, b, x, y = map(int, input().split())
    print('Yes' if b >= a-y and b <= a+x else 'No')