There are three cities and thus three EVMs. An insider told Chef that his party got A, B, C votes respectively in these three cities according to the EVMs. Also, the total number of votes cast are P, Q, R respectively for the three cities. 

Chef, being the party leader, can hack at most one EVM so that his party wins. On hacking a particular EVM all the votes cast in that EVM are counted in favor of Chef's party. 

A party must secure strictly more than half of the total number of votes cast in order to be considered the winner. Can Chef achieve his objective of winning by hacking at most one EVM?

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

- The first line of input contains an integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case consists of a single line of input, containing six space-separated integers — in order, A, B, C, P, Q, R.

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

For each test case, output in a single line the answer — "YES", if Chef can win the election after hacking at most one EVM and "NO" if not.

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 ≤ 5 \cdot 10^{3}$
$0 ≤ A < P ≤ 100$
$0 ≤ B < Q ≤ 100$
$0 ≤ C < R ≤ 100$

----- Sample Input 1 ------ 
3
1 1 1 3 3 3
49 1 49 50 100 50
0 0 0 1 1 1

----- Sample Output 1 ------ 
YES
YES
NO

----- explanation 1 ------ 
Test case $1$: Chef can hack any EVM, thus getting a total of $3 + 1 + 1 = 5$ votes which is more than $\frac{3 + 3 + 3}{2} = 4.5$ votes.

Test case $2$: Only hacking the second EVM works, getting a total of $49 + 100 + 49 = 198$ votes which is more than $\frac{50 + 100 + 50}{2} = 100$ votes.

Test case $3$: None of the EVM's can help Chef in winning the election, since maximum number of votes he can secure by doing so is $1 + 0 + 0 = 1$ which is less than $\frac{1 + 1 + 1}{2} = 1.5$.

Source: codechef | Difficulty: EASY
Tags: Constructive algorithms

Mathematics

Ad-hoc


Solutions:
for _ in range(int(input())):
	(a, b, c, p, q, r) = map(int, input().split())
	req = (p + q + r) / 2
	got = a + b + c
	for (i, j) in ((a, p), (b, q), (c, r)):
		if got - i + j > req:
			print('YES')
			break
	else:
		print('NO')


for _ in range(int(input())):
	(a, b, c, p, q, r) = map(int, input().split())
	(d1, d2, d3) = (p - a, q - b, r - c)
	if d1 >= d2 and d1 >= d3:
		if p + b + c > (p + q + r) / 2:
			print('YES')
		else:
			print('NO')
	elif d2 >= d1 and d2 >= d3:
		if a + q + c > (p + q + r) / 2:
			print('YES')
		else:
			print('NO')
	elif a + b + r > (p + q + r) / 2:
		print('YES')
	else:
		print('NO')


t = int(input())
for bunny in range(t):
	(a, b, c, p, q, r) = map(int, input().split())
	s = (p + q + r) / 2
	if a + b + c > s:
		print('YES')
	elif p + b + c > s:
		print('YES')
	elif q + a + c > s:
		print('YES')
	elif r + a + b > s:
		print('YES')
	else:
		print('NO')


import math
for _ in range(int(input())):
	(a, b, c, p, q, r) = map(int, input().split())
	d = a + b + c
	a = p - a
	b = q - b
	c = r - c
	m = (p + q + r) / 2
	if float(d + a) > m or float(d + b) > m or float(d + c) > m:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	for i in range(3):
		temp = 0
		p = l[0] + l[1] + l[2] + (l[i + 3] - l[i])
		p1 = l[3] + l[4] + l[5]
		if p > p1 / 2:
			l[i] = l[i + 3]
			temp = 1
			break
	if temp == 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(a, b, c, p, q, r) = map(int, input().split())
	tot = (p + q + r) / 2
	if a + b + c > tot:
		print('YES')
	elif p + b + c > tot:
		print('YES')
	elif a + q + c > tot:
		print('YES')
	elif a + b + r > tot:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(a, b, c, p, q, r) = map(int, input().split())
	avg = (p + q + r) / 2
	if p + b + c > avg or a + q + c > avg or a + b + r > avg:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	a = list(map(int, input().split(' ')))
	y = a[3:]
	x = a[:3]
	temp = a[:3]
	n = 0
	while sum(y) / 2 >= sum(x) and n < 3:
		x = a[:3]
		x[n] = y[n]
		n += 1
	if sum(y) / 2 < sum(x):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(A, B, C, P, Q, R) = map(int, input().split())
	avg = (P + Q + R) / 2
	if A + B + C > avg:
		print('YES')
	elif P + B + C > avg:
		print('YES')
	elif A + Q + C > avg:
		print('YES')
	elif A + B + R > avg:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(a, b, c, d, e, f) = map(int, input().split())
	x = a + b + f
	y = a + c + e
	z = d + b + c
	u = (d + e + f) / 2
	if x > u or y > u or z > u:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	(a, b, c, p, q, r) = map(int, input().split())
	req = (p + q + r) / 2 - (a + b + c)
	if q - b > req or p - a > req or r - c > req:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(A, B, C, P, Q, R) = map(int, input().split())
	n = (P + Q + R) // 2
	if A + B + C > n:
		print('YES')
	elif P + B + C > n:
		print('YES')
	elif A + Q + C > n:
		print('YES')
	elif A + B + R > n:
		print('YES')
	else:
		print('NO')


import math
for _ in range(int(input())):
	(vijay, jnau, buddy, p1, q1, r1) = map(int, input().split())
	d = vijay + jnau + buddy
	vijay = p1 - vijay
	jnau = q1 - jnau
	buddy = r1 - buddy
	m = (p1 + q1 + r1) / 2
	if float(d + vijay) > m or float(d + jnau) > m or float(d + buddy) > m:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	inp = list(map(int, input().split()))
	chefs = inp[0:3]
	total = inp[3:]
	minvote = round(sum(total) / 2, 1)
	flag = False
	for (i, element) in enumerate(total):
		if sum(chefs) - chefs[i] + element > minvote:
			print('YES')
			flag = True
			break
	if not flag:
		print('NO')


for t in range(int(input())):
	l = list(map(int, input().split()))
	nums_of_EVMs = 3
	max_diff = 0
	for i in range(nums_of_EVMs):
		diff = l[i + 3] - l[i]
		if diff > max_diff:
			max_diff = diff
			max_pos = i
	if l[0] + l[1] + l[2] - l[max_pos] + l[max_pos + 3] > (l[3] + l[4] + l[5]) / 2:
		ans = 'YES'
	else:
		ans = 'NO'
	print(ans)


for _ in range(int(input())):
	a = list(map(int, input().strip().split()))
	totalVotes = a[3] + a[4] + a[5]
	currentVotes = a[0] + a[1] + a[2]
	if max(a[3] - a[0], max(a[4] - a[1], a[5] - a[2])) + currentVotes > totalVotes / 2:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	(a, b, c, p, q, r) = list(map(int, input().split()))
	votes = max(p + b + c, a + q + c, a + b + r)
	maj = (p + q + r) / 2
	if votes > maj:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(A, B, C, P, Q, R) = map(int, input().split())
	res1 = P + B + C
	res2 = A + Q + C
	res3 = A + B + R
	res = max(res1, res2, res3)
	if res > (P + Q + R) / 2:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(a, b, c, p, q, r) = map(int, input().split())
	a1 = p + b + c
	a2 = a + q + c
	a3 = a + b + r
	avg = (p + q + r) / 2
	if float(a1) > avg or float(a2) > avg or float(a3) > avg:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(a, b, c, p, q, r) = map(int, input().split())
	max1 = max(p, q, r)
	s = b + c + p
	t = a + c + q
	u = a + b + r
	avg = (p + q + r) / 2
	if s > avg or t > avg or u > avg:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(a, b, c, p, q, r) = map(int, input().split())
	max1 = max(p, q, r)
	s1 = b + c + p
	s2 = a + c + q
	s3 = a + b + r
	avg = (p + q + r) / 2
	if s1 > avg or s2 > avg or s3 > avg:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(a, b, c, p, q, r) = map(int, input().split())
	mean = float((p + q + r) / 2)
	if a + b + c > mean:
		print('YES')
	elif a + b + r > mean or p + b + c > mean or a + q + c > mean:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(a, b, c, p, q, r) = map(int, input().split())
	d = a + b + c
	a = p - a
	b = q - b
	c = r - c
	m = (p + q + r) * 1.0 / 2
	if d + a > m or d + b > m or d + c > m:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(a, b, c, p, q, r) = map(int, input().split())
	n = (p + q + r) / 2
	l = []
	l.append(p + b + c)
	l.append(a + q + c)
	l.append(a + b + r)
	print('YES' if max(l) > n else 'NO')


for _ in range(int(input())):
	(a, b, c, p, q, r) = map(int, input().split())
	mini = (p + q + r) / 2
	if p + b + c > mini or a + q + c > mini or a + b + r > mini:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	votes = input().split(' ')
	[a, b, c, p, q, r] = [int(votes[0]), int(votes[1]), int(votes[2]), int(votes[3]), int(votes[4]), int(votes[5])]
	if 2 * (a + b + c) > p + q + r:
		print('YES')
	elif 2 * (p + b + c) > p + q + r or 2 * (a + q + c) > p + q + r or 2 * (a + b + r) > p + q + r:
		print('YES')
	else:
		print('NO')


t = int(input())
for tc in range(t):
	(a, b, c, p, q, r) = map(int, input().split())
	d = (p + q + r) // 2
	n = a + b + c + max(p - a, q - b, r - c)
	if d < n:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	(A, B, C, P, Q, R) = map(int, input().split())
	total_votes = P + Q + R
	votes_for_party = A + B + C
	max_possible_votes = A + B + C + max(P - A, Q - B, R - C)
	if max_possible_votes > total_votes / 2:
		print('YES')
	else:
		print('NO')


x = int(input())
reg = []
for ll in range(0, x):
	ort = str(input())
	iil = ort.split(' ')
	tvc = []
	for nnj in iil:
		tvc.append(int(nnj))
	reg.append(tvc)
for eex in reg:
	hnkl = eex[0] + eex[1] + eex[2]
	ynr = eex[3] + eex[4] + eex[5]
	ipy = ynr / 2 - hnkl
	irg = [eex[0], eex[1], eex[2]]
	uure = [eex[3], eex[4], eex[5]]
	mp = 'NO'
	for ilrt in range(0, 3):
		upr = uure[ilrt] - irg[ilrt]
		if upr > ipy:
			mp = 'YES'
			break
	print(mp)


T = int(input())
for i in range(T):
	(A, B, C, P, Q, R) = map(int, input().split())
	y = (P + Q + R) / 2
	u = max(P, Q, R)
	if P + B + C > y or A + Q + C > y or A + B + R > y or (A + B + C > y):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(a, b, c, x, y, z) = map(int, input().split())
	l = []
	l.append(x - a)
	l.append(y - b)
	l.append(z - c)
	if l[0] == max(l):
		if b + c + x > (x + y + z) / 2:
			print('YES')
		else:
			print('NO')
	elif l[1] == max(l):
		if y + c + a > (x + y + z) / 2:
			print('YES')
		else:
			print('NO')
	elif b + z + a > (x + y + z) / 2:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(a, b, c, p, q, r) = map(int, input().split())
	Max = max(p - a, q - b, r - c)
	TotalVotes = p + q + r
	need = TotalVotes / 2 - (a + b + c)
	if Max > need:
		print('YES')
	else:
		print('NO')


for tc in range(int(input())):
	(a, b, c, p, q, r) = map(int, input().split())
	totvot = p + q + r
	chefvot = a + b + c
	req = totvot // 2 - chefvot
	maxvote = max(p - a, q - b, r - c)
	if maxvote > req:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(a, b, c, x, y, z) = map(int, input().split())
	if max(x - a, y - b, z - c) + a + b + c > (x + y + z) / 2:
		print('YES')
	else:
		print('NO')


for u in range(int(input())):
	l = [int(i) for i in input().split()]
	l = [(l[i + 3], l[i]) for i in range(3)]
	l.sort()
	if (l[0][0] + l[1][0] + l[2][0]) / 2 < l[0][1] + l[1][1] + l[2][0]:
		print('YES')
	elif (l[0][0] + l[1][0] + l[2][0]) / 2 < l[0][1] + l[1][0] + l[2][1]:
		print('YES')
	elif (l[0][0] + l[1][0] + l[2][0]) / 2 < l[0][0] + l[1][1] + l[2][1]:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	l1 = list(map(int, input().split()))
	l2 = l1[:3]
	l3 = l1[3:]
	if l3[0] + l2[1] + l2[2] > sum(l3) / 2 or l3[1] + l2[0] + l2[2] > sum(l3) / 2 or l3[2] + l2[1] + l2[0] > sum(l3) / 2:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(a, b, c, p, q, r) = list(map(int, input().split()))
	n = (p + q + r) / 2
	Sum = a + b + c
	maxi = max(p - a, q - b, r - c)
	if Sum + maxi > n:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	(a, b, c, p, q, r) = map(int, input().strip().split())
	s = (p + q + r) / 2
	ans = a + b + c
	if ans > s or ans - a + p > s or ans - b + q > s or (ans - c + r > s):
		print('YES')
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	(A, B, C, P, Q, R) = list(map(int, input().split(' ')))
	Qu = (P + Q + R) / 2
	V = A + B + C
	if V > Qu or V - A + P > Qu or V - B + Q > Qu or (V - C + R > Qu):
		print('YES')
	else:
		print('NO')


T = int(input())
while T:
	T -= 1
	(A, B, C, P, Q, R) = list(map(int, input().split(' ')))
	Qu = (P + Q + R) / 2
	V = A + B + C
	if V > Qu or V - A + P > Qu or V - B + Q > Qu or (V - C + R > Qu):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	a = [int(x) for x in input().split()]
	b = a[:3]
	c = a[3:]
	d = []
	for i in range(3):
		d.append(c[i] - b[i])
	if (sum(b) + max(d)) * 2 > sum(c):
		print('YES')
	else:
		print('NO')


def main():
	T = int(input())
	for _ in range(T):
		arr = list(map(int, input().split()))[:6]
		d = sum(arr[:3])
		a = arr[3] - arr[0]
		b = arr[4] - arr[1]
		c = arr[5] - arr[2]
		p = sum(arr[3:]) / 2
		print('YES' if d + a > p or d + b > p or d + c > p else 'NO')
main()


t = int(input())
for i in range(0, t):
	(a, b, c, p, q, r) = map(int, input().split())
	vot = (p + q + r) / 2
	if a + b + r > vot or a + c + q > vot or b + c + p > vot:
		print('YES')
	else:
		print('NO')


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


t = int(input())
for i in range(t):
	(a, b, c, p, q, r) = map(int, input().split())
	w = (p + q + r) / 2
	l = [a, b, c]
	x = sum(l) / 2
	a = p - a
	b = q - b
	c = r - c
	if sum(l) + a > w or sum(l) + b > w or sum(l) + c > w:
		print('YES')
	else:
		print('NO')


t = int(int(input()))
while t != 0:
	(a, b, c, p, q, r) = map(int, input().split())
	need = (p + q + r) / 2
	sum = a + b + c
	if sum >= need:
		print('YES')
	elif a + b + r > need or p + b + c > need or a + q + c > need:
		print('YES')
	else:
		print('NO')
	t -= 1


t = int(input())
while t > 0:
	(a, b, c, p, q, r) = map(int, input().split())
	avg = (p + q + r) / 2
	su = a + b + c
	if su > avg:
		print('YES')
	elif a + b + r > avg or a + q + c > avg or p + b + c > avg:
		print('YES')
	else:
		print('NO')
	t = t - 1


for t in range(int(input())):
	(a, b, c, p, q, r) = [int(i) for i in input().split()]
	hailee = (p + q + r) / 2
	if p + b + c > hailee:
		print('YES')
	elif a + q + c > hailee:
		print('YES')
	elif r + a + b > hailee:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	(A, B, C, P, Q, R) = map(int, input().split())
	if A + B + C <= (P + Q + R) / 2:
		max_votes = max(P - A, Q - B, R - C)
		if A + B + C + max_votes <= (P + Q + R) / 2:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')