-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA.py
82 lines (54 loc) · 1.25 KB
/
A.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import sys
sys.stdout = open('output1.txt','w')
sys.stdin = open('input1.txt','r')
def solveYES_NO(n,k,array):
sorting = sorted(array,reverse=True)
if n==1:
return sorting[0] <=k
if n==2: # minimum is last
return sorting[1] <=k
total = 0
minimum = sorting[-1]
#1st case
total = minimum + ( (minimum * 2) * (n-2) )
# print(total)
return total<=k
# # print('here')
# return True
# r
# # 2nd case
# total = 0
# if n%2==0:
# for i in range(1, len(sorting)):
# total += (sorting[i] *2)
# else:
# for i in range(1, len(sorting) - 1):
# total += (sorting[i] *2)
# total += sorting[-1]
# return total<=k
# 4 3 2 1
#
# 4 3 1 ->
# 10, 5 ,2 ,1 -> 1+1 ==2,
# 10,9,9,9 -> 9+9, 9+9, 9,| 10,9,9 -> 9+9, 9
# 10,9,9,9,9
#[28, 20, 17, 16, 15]
# 15
#10 9 8
# 9+9, 8
#9+9, 8
#10,9,8
#10,9,8
# 9, 8
# 9+9, 8
# 10,9,8,6
# 9,
for t in range(int(input())):
n, k = map(int, input().split())
array = []
for i in range(n):
array.append( int(input()) )
if solveYES_NO(n,k,array):
print(f"Case #{t+1}: YES")
else:
print(f"Case #{t+1}: NO")