PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: jeevanjyot
Tester & Editorialist: iceknight1093
DIFFICULTY:
578
PREREQUISITES:
None
PROBLEM:
Four companies — A, B, C, and D — made profits of rupees P, Q, R, and S lakh respectively, in the last year.
There’s a monopoly in the market if the profit made by one company is strictly larger than the sum of profits of the others.
Is there a monopoly in the market?
EXPLANATION:
Check whether any of the four companies satisfies the monopoly condition, i.e, check if any one of
- A \gt B + C + D
- B \gt A + C + D
- C \gt A + B + D
- D \gt A + B + C
are true.
If at least one of them is true, the answer is Yes
; else the answer is No
.
For a slightly simpler solution, notice that it’s enough to check whether the company with largest profit satisfies the condition.
This gives us the condition \max(A, B, C, D) \gt A + B + C + D - \max(A, B, C, D), or 2\max(A, B, C, D) \gt A + B + C + D, which is a bit cleaner to implement since it only requires one if
condition.
TIME COMPLEXITY
\mathcal{O}(1) per test case.
CODE:
Editorialist's code (Python)
for _ in range(int(input())):
a, b, c, d = map(int, input().split())
print('Yes' if 2*max(a, b, c, d) > a + b + c + d else 'No')