forked from hackerearthclub/CODE2RACE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReductionGame.py
73 lines (44 loc) · 1.34 KB
/
ReductionGame.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
#Author: Nirupam Gunwal
# Issue Solve Reduction Game #573
#Detailed Solution to the Problem Described at https://github.com/hackerearthclub/CODE2RACE/blob/master/ASSIGNMENTS/Reduction%20Game.md
# in Python 3
def answer(arr):
ntestcase = arr[0]
narr = []
k = []
sumfinal = []
arrn = []
loopcount = len(arr)
i = 1
while i < loopcount :
n = arr[i]
narr.append(n)
k.append(arr[i+1])
arrlist = arr[i + 2 : i + n + 2]
arrn.append(arrlist)
i = i + n + 2
for i in range(ntestcase):
sortedarray = sorted(arrn[i])
j = 0
while j < len(sortedarray) - 1:
while min(sortedarray[j],sortedarray[j+1]) > k[i]:
sortedarray[j] = sortedarray [j] - 1
sortedarray[j+1] = sortedarray [j+1] - 1
j = j + 1
sumfinal.append(sum(sortedarray))
print("Output:")
print(sumfinal)
def main():
print("Use Test Case OR Input Your Own .(y for Your Own Input else Test Case will be considered)")
if(str(input()) == 'y'):
print("Test Case Selected")
arr = [3,2,1,1,2,2,1,2,2,3,1,2,3,2]
else:
print("Input Selected .Give the input according to the question and use dont use spaces to seperate numbers :")
print(" Input Should be of the format like this : 32112212231232 (No spaces)")
arr = list(input())
for i in range(len(arr)):
arr[i] = int(arr[i])
answer(arr)
if __name__ == '__main__':
main()