-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathchef_and_icecream.py
More file actions
32 lines (28 loc) · 849 Bytes
/
chef_and_icecream.py
File metadata and controls
32 lines (28 loc) · 849 Bytes
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
def can_icecream_be_served(A):
shops_money = [0]*4 # 0:Rs 5 , 1:Rs 10 , 2:Rs 15 , 3:Total
for i in A:
balance = int(i)-5
if(balance == 0):
shops_money[0] += 1
elif(balance == 5):
if(shops_money[0] < 1):
return("NO")
else:
shops_money[0] -= 1
shops_money[1] += 1
else:
if(shops_money[1] < 1):
if(shops_money[0] < 2):
return("NO")
else:
shops_money[0] -= 2
shops_money[2] += 1
else:
shops_money[1] -= 1
shops_money[2] += 1
return("YES")
T = int(input())
for i in range(T):
N = int(input())
A = input().split(" ")
print(can_icecream_be_served(A))