-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathioi09p5.py
40 lines (33 loc) · 872 Bytes
/
ioi09p5.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
import sys
from collections import deque
inp = sys.stdin.readlines()
n, m = list(map(int, inp.pop(0).strip('\n').split(' ')))
rates = deque([])
cars = deque([])
i = deque([])
spots = deque([])
queue = deque([])
money = 0
for x in range(n):
rates.append(eval(inp.pop(0)))
spots.append(None)
for x in range(m):
cars.append(eval(inp.pop(0)))
for x in range(m*2):
i.append(eval(inp.pop(0)))
for x in range(len(i)):
if i[x] > 0:
if None not in spots:
queue.append(i[x])
else:
k = spots.index(None)
money += rates[k]*cars[i[x]-1]
spots[k] = i[x]
else:
spots[spots.index(abs(i[x]))] = None
if len(queue) != 0:
k = spots.index(None)
money += rates[k]*cars[queue[0]-1]
spots[k] = queue[0]
queue.popleft()
print(money)