-
Notifications
You must be signed in to change notification settings - Fork 0
/
d1000000.py
95 lines (73 loc) · 2.3 KB
/
d1000000.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
83
84
85
86
87
88
89
90
91
92
93
94
95
T = int(input())
for t in range(T):
N = int(input())
dices = input().split()
dices = [int(d) for d in dices]
dices.sort()
dices_diff = [dices[i+1]-dices[i] for i in range(N-1)]
dices_diff.append(0)
# print(dices)
# print(dices_diff)
target_ind = 0
count = None
total_dice = 0
for i in range(N):
# print("N: ", i)
if dices_diff[i] != 0:
if count == None:
# print("count none")
target_ind = i
# print("target ind: ", target_ind)
elif count<=0:
# print("count: ". count)
target_ind = i
# print("target: ", target_ind)
count = dices_diff[i]
# print("new count: ", count)
else:
if count==None:
pass
else:
# print("count reducing: ", count)
count = count - 1
# total_dice = N - target_ind
if count == None and target_ind == 0:
target_ind = N - 1
# print("target ind", target_ind)
total_dice = 0
target_value = dices[target_ind]
# print("target value", target_value)
i = target_ind
while i<N:
# print("i", i)
# print("target value", target_value)
# print("dices", dices[i])
if target_value > dices[-1]:
# print("breaking")
break
if target_value<=dices[i]:
# print("incrementing")
total_dice = total_dice + 1
target_value = target_value + 1
# print("total dice", total_dice)
# print("target_value:", target_value)
else:
break
i = i + 1
# print('total_dice', total_dice)
target_value = dices[target_ind] - 1
# print("target value", target_value)
for i in range(target_ind-1, -1, -1):
# print("i", i)
if target_value<1:
break
if target_value <= dices[i]:
# print("targe:", target_value)
# print("dice", dices[i])
total_dice = total_dice + 1
target_value = target_value - 1
else:
break
print("Case #" + str(t+1) + ": " + str(total_dice))
# print(total_dice)
# 2 2 2 2 6 6 6 6 3 3 3 3 7 7 7 7 7 7 7 7