SURPLUS - Editorial

PROBLEM LINK:

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

Author: notsoloud
Tester: tabr
Editorialist: iceknight1093

DIFFICULTY:

695

PREREQUISITES:

None

PROBLEM:

Three countries A, B, C trade only among themselves.
A exports A_1 units of goods and imports A_2 units.
B exports B_1 units of goods and imports B_2 units.
Is C in a trade surplus?

EXPLANATION:

At first glance, the question seems weird — after all, we don’t have any direct information about country C's trades.
However, the key point here is that A, B, C trade only among themselves. This means that the total exports of all three countries equals the total imports of all three countries (because any goods exported from one country must be imported in another one).

So, let C export C_1 units and import C_2 units. We know that:

A_1 + B_1 + C_1 = A_2 + B_2 + C_2 \ \ \ \ \ \ \ \ \ \ \text{(Total exports = Total imports)}

Rearranging this a bit,

C_1 - C_2 = A_2 + B_2 - A_1 - B_1

Notice that the LHS is exactly the value we want to compute, i.e, the net export of country C.
On the other hand, all 4 values in the RHS are given to us in the input, so we can directly compute that value.

So, we know C_1 - C_2. All that remains is to check whether it’s positive or not, and print Yes or No appropriately.

TIME COMPLEXITY

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (Python)
for _ in range(int(input())):
    a1, a2, b1, b2 = map(int, input().split())
    print('Yes' if (a1+b1-a2-b2) < 0 else 'No')