답안 #549913

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
549913 2022-04-16T20:21:43 Z beaconmc Garage (IOI09_garage) PyPy 3
100 / 100
176 ms 26336 KB
from collections import deque
d = deque()

n,m = map(int, input().split())
rates = []
weights = []
for i in range(n):
    rates.append(int(input()))

for i in range(m):
    weights.append(int(input()))

ans = 0
spots = [-1 for i in range(n)]

for i in range(2*m):
    a = int(input())
    if a>0:
        d.append(a)
    else:
        a = -a
        for i in range(n):
            if spots[i] == a:
                spots[i] = -1
                break
    while len(d):
        sus = d.popleft()
        realsus = False
        for i in range(n):
            if spots[i] == -1:
                realsus = True
                spots[i] = sus
                ans += weights[sus-1]*rates[i]
                break
        if realsus == False:
            d.appendleft(sus)
            break
    
        
print(ans)
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 18708 KB Output is correct
2 Correct 41 ms 18604 KB Output is correct
3 Correct 41 ms 18556 KB Output is correct
4 Correct 42 ms 18652 KB Output is correct
5 Correct 45 ms 18556 KB Output is correct
6 Correct 48 ms 18732 KB Output is correct
7 Correct 49 ms 18688 KB Output is correct
8 Correct 54 ms 18812 KB Output is correct
9 Correct 68 ms 18748 KB Output is correct
10 Correct 81 ms 20264 KB Output is correct
11 Correct 74 ms 19584 KB Output is correct
12 Correct 96 ms 23208 KB Output is correct
13 Correct 94 ms 20180 KB Output is correct
14 Correct 134 ms 22896 KB Output is correct
15 Correct 121 ms 24324 KB Output is correct
16 Correct 135 ms 26152 KB Output is correct
17 Correct 156 ms 26264 KB Output is correct
18 Correct 176 ms 26336 KB Output is correct
19 Correct 127 ms 24044 KB Output is correct
20 Correct 153 ms 26132 KB Output is correct