Untitled
unknown
python
2 years ago
811 B
3
Indexable
Never
places, nRides, nGrps = [*map(int,input().split())] queue = [] for i in range(nGrps): queue.append((int(input()), i)) rides = [] r = 0 head = 0 ans = 0 while r < nRides: ride = [] nPpl = 0 g = 0 while nPpl + queue[head][0] <= places and g < nGrps: ride.append(queue[head]) nPpl += queue[head][0] head = (head + 1) % nGrps g+=1 if ride in rides: ridesLeft = nRides - r loop = rides[rides.index(ride):] loopLen = len(loop) sumLoopDiv = sum(sum(gp[0] for gp in rd) for rd in loop) * (ridesLeft // loopLen) sumLoopMod = sum(sum(gp[0] for gp in rd) for rd in loop[:ridesLeft % loopLen]) ans += sumLoopDiv + sumLoopMod break else: rides.append(ride) ans += nPpl r += 1 print(ans)