Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Chef has 3 bags that she wants to take on a flight. They weigh A, B, and C kgs respectively. She wants to check-in exactly two of these bags and carry the remaining one bag with her.

The airline restrictions says that the total sum of the weights of the bags that are checked-in cannot exceed D kgs and the weight of the bag which is carried cannot exceed E kgs. Find if Chef can take all the three bags on the flight.

------ Input Format ------ 

- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each testcase contains a single line of input, five space separated integers A, B, C, D, E.

------ Output Format ------ 

For each testcase, output in a single line answer "YES" if Chef can take all the three bags with her or "NO" if she cannot.

You may print each character of the string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).

------ Constraints ------ 

$1 ≤ T ≤ 36000$
$1 ≤ A, B, C ≤ 10$
$15 ≤ D ≤ 20$
$5 ≤ E ≤ 10$

------ subtasks ------ 

Subtask #1 (100 points): original constraints

----- Sample Input 1 ------ 
3
1 1 1 15 5
8 7 6 15 5
8 5 7 15 6
----- Sample Output 1 ------ 
YES
NO
YES
----- explanation 1 ------ 
Test case $1$: Chef can check-in the first and second bag (since $1 + 1 = 2 ≤ 15$) and carry the third bag with her (since $1 ≤ 5$).

Test case $2$: None of the three bags can be carried in hand without violating the airport restrictions.

Test case $3$: Chef can check-in the first and the third bag (since $8 + 7 ≤ 15$) and carry the second bag with her (since $5 ≤ 6$).

Source: codechef | Difficulty: EASY
Tags: Mathematics

Complete search

Implementation

Ad-hoc


Solutions:
for i in range(int(input())):
	(a, b, c, d, e) = map(int, input().split())
	s1 = a + b
	s2 = b + c
	s3 = c + a
	if s1 <= d and c <= e:
		print('YES')
	elif s2 <= d and a <= e:
		print('YES')
	elif s3 <= d and b <= e:
		print('YES')
	else:
		print('NO')


def sol(a, b, c, d, e):
	l = [a, b, c]
	l.sort()
	if l[0] <= e and l[1] + l[2] <= d:
		print('YES')
	elif l[1] <= e and l[0] + l[2] <= d:
		print('YES')
	elif l[2] <= e and l[0] + l[1] <= d:
		print('YES')
	else:
		print('NO')
for i in range(int(input())):
	(a, b, c, d, e) = map(int, input().split())
	sol(a, b, c, d, e)


for _ in range(int(input())):
	(a, b, c, d, e) = map(int, input().split())
	if a + b <= d and c <= e or (a + c <= d and b <= e) or (b + c <= d and a <= e):
		print('YES')
	else:
		print('NO')


T = int(input())
for T in range(T):
	(a, b, c, d, e) = map(int, input().split())
	if a + b <= d and c <= e:
		print('YES')
	elif c + b <= d and a <= e:
		print('YES')
	elif a + c <= d and b <= e:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(A, B, C, D, E) = map(int, input().split())
	if A + B <= D and C <= E:
		print('YES')
	elif A + C <= D and B <= E:
		print('YES')
	elif B + C <= D and A <= E:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	l = [int(i) for i in input().split()]
	a = []
	a.append(l[0])
	a.append(l[1])
	a.append(l[2])
	a = sorted(a)
	if a[2] <= l[4]:
		d = l[3] - a[1]
	else:
		d = l[3] - a[2]
	if a[0] <= d and a[1] <= l[4] or (a[1] <= d and a[0] <= l[4]):
		print('YES')
	else:
		print('NO')


T = int(input())
for i in range(T):
	(A, B, C, D, E) = map(int, input().split())
	if A + B <= D and C <= E or (A + C <= D and B <= E) or (B + C <= D and A <= E):
		print('YES')
	else:
		print('NO')


def perhitungan(tas1, tas2, tas3, syarat_checkin, syarat_dibawa):
	kondisi1 = a + b <= d and c <= e
	kondisi2 = b + c <= d and a <= e
	kondisi3 = c + a <= d and b <= e
	if kondisi1 or kondisi2 or kondisi3:
		print('YES')
	else:
		print('NO')
T = int(input())
for i in range(T):
	(a, b, c, d, e) = map(int, input().split(' '))
	perhitungan(a, b, c, d, e)


testcase = int(input())
for t in range(testcase):
	(p, q, r, s, t) = map(int, input().split())
	c1 = p + q <= s and r <= t
	c2 = q + r <= s and p <= t
	c3 = r + p <= s and q <= t
	if c1 or c2 or c3:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(a, b, c, d, e) = map(int, input().split())
	s = a + b + c
	k = [x for x in [a, b, c] if x <= e and s - x <= d]
	if k:
		print('YES')
	else:
		print('NO')


def airlines(a, b, c, d, e):
	if a + b <= d and c <= e:
		return 'YES'
	elif a + c <= d and b <= e:
		return 'YES'
	elif c + b <= d and a <= e:
		return 'YES'
	else:
		return 'NO'
t = int(input())
for i in range(t):
	(a, b, c, d, e) = map(int, input().split())
	print(airlines(a, b, c, d, e))


n = int(input())
for i in range(n):
	l = list(map(int, input().split()))
	if l[0] + l[1] <= l[3] and l[2] <= l[4]:
		print('YES')
	elif l[1] + l[2] <= l[3] and l[0] <= l[4]:
		print('YES')
	elif l[0] + l[2] <= l[3] and l[1] <= l[4]:
		print('YES')
	else:
		print('NO')


n = input()
for _ in range(int(n)):
	p = input().split()
	if int(p[0]) + int(p[1]) <= int(p[3]) and int(p[2]) <= int(p[4]):
		print('YES')
	elif int(p[0]) + int(p[2]) <= int(p[3]) and int(p[1]) <= int(p[4]):
		print('YES')
	elif int(p[1]) + int(p[2]) <= int(p[3]) and int(p[0]) <= int(p[4]):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(a, b, c, d, e) = list(map(int, input().split()))
	if a + b <= d and c <= e or (a + c <= d and b <= e) or (b + c <= d and a <= e):
		print('YES')
	else:
		print('NO')


f = int(input())
for i in range(0, f):
	(a, b, c, d, e) = map(int, input().split())
	if a + b <= d and c <= e or (b + c <= d and a <= e) or (a + c <= d and b <= e):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(*bag, d, e) = map(int, input().split())
	ok = False
	order = [0, 1, 2]
	for _ in range(3):
		if bag[order[0]] + bag[order[1]] <= d and bag[order[2]] <= e:
			ok = True
			break
		order = [order[-1]] + order[:-1]
	print('YES' if ok else 'NO')


def air_res(a, b, c, d, e):
	if a + b <= d and c <= e or (b + c <= d and a <= e) or (a + c <= d and b <= e):
		print('YES')
	else:
		print('NO')
T = int(input())
for i in range(T):
	(a, b, c, d, e) = map(int, input().split())
	air_res(a, b, c, d, e)


t = int(input())
for i in range(t):
	(A, B, C, D, E) = map(int, input().split())
	K = [A, B, C]
	K.sort()
	if min(K) > E:
		print('NO')
	elif K[1] + K[2] <= D and min(K) <= E:
		print('YES')
	elif K[0] + K[1] <= D and max(K) <= E:
		print('YES')
	elif K[0] + K[2] <= D and K[1] <= E:
		print('YES')
	else:
		print('NO')


T = int(input())
for t in range(0, T):
	(a, b, c, d, e) = map(int, input().split())
	c1 = a + b <= d and c <= e
	c2 = a + c <= d and b <= e
	c3 = b + c <= d and a <= e
	if c1 or c2 or c3:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(a, b, c, d, e) = map(int, input().split())
	p = a + b
	q = b + c
	r = a + c
	if p <= d and c <= e:
		print('YES')
	elif q <= d and a <= e:
		print('YES')
	elif r <= d and b <= e:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	(A, B, C, D, E) = map(int, input().split())
	if A + B <= D and C <= E or (A + C <= D and B <= E) or (B + C <= D and A <= E):
		print('YES')
		pass
	else:
		print('NO')
		pass