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

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

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Stop Buying Cheap Alternatives This Viral Kitchen Gadgets Is the Real Deal

📢 As an Amazon Associate, I earn from qualifying purchases.I stumbled across this while desperately trying to fix a recurring problem in my routine....

The Agentic Shift: How Meta Is Building the Infrastructure for AI-Powered Marketing

The digital advertising landscape is standing at the precipice of a massive structural evolution known as the agentic shift. As artificial intelligence advances beyond...

I Tried Viral Kitchen Gadgets For 30 Days Here Is the Honest Truth

📢 As an Amazon Associate, I earn from qualifying purchases.Most products in this category disappoint within weeks. Cheap materials, vague instructions, and results that...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!