https://i1.wp.com/eblogarithm.com/wp-content/uploads/2017/07/Playrix-Codescapes-Cup-Codeforces-Round-413-rated-Div-1--Div-2-problem-B-Tshirt-buying-Solution-In-CC1.png?fit=640%2C360

Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2), problem: (B) T-shirt buying Solution In C/C++

from heapq import heappush, heappop

n = input()
p = map(int, raw_input().split())
a = map(int, raw_input().split())
b = map(int, raw_input().split())
m = input()
c = map(int, raw_input().split())
colors = {}
for i in range(1, 4): colors[i] = []
for i in range(n):
heappush(colors[a[i]], (p[i], i))
if a[i] != b[i]: heappush(colors[b[i]], (p[i], i))
available = [1] * n
for i in range(m):
while True:
if len(colors[c[i]]) == 0:
print -1,
break
else:
price, index = heappop(colors[c[i]])
if available[index]:
available[index] = 0
print price,
break

(Visited 4 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: