-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPython3.py
49 lines (37 loc) · 1.16 KB
/
Python3.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
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
earnings = 0
groups = []
cacheEarning = dict()
cacheIndex = dict()
index = int(0)
l, c, n = [int(i) for i in input().split()]
for i in range(n):
pi = int(input())
groups.append(pi)
# Write an action using print
# To debug: print("Debug messages...", file=sys.stderr)
for i in range(c):
placeCount = 0
beginIndex = index
beginIndexB = False
while placeCount <= l:
if beginIndex in cacheEarning:
earnings += cacheEarning[beginIndex]
index = cacheIndex[beginIndex]
break
if beginIndex == index:
if beginIndexB: break
if not beginIndexB: beginIndexB = True
if placeCount + groups[index] <= l:
placeCount += groups[index]
if index + 1 < len(groups): index += 1
else: index = 0
else: break
earnings += placeCount
if not beginIndex in cacheEarning:
cacheEarning[beginIndex] = placeCount
cacheIndex[beginIndex] = index
print(earnings)