-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path19_09_4.py
41 lines (40 loc) · 1.29 KB
/
19_09_4.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
41
from heapq import heapify, heappop, heappush
import re
m, n = [int(it) for it in input().rstrip().split(' ')]
ban = set()
inf = dict()
goods = []
for i in range(n):
ids, score = [int(it) for it in input().rstrip().split(' ')]
for j in range(m):
goods.append((-score, j, ids))
inf[(j, ids)] = -score
op_num = int(input())
heapify(goods)
for i in range(op_num):
ipts = [int(it) for it in re.split(' +', input().rstrip())]
if ipts[0] == 1:
heappush(goods, (-ipts[3], ipts[1], ipts[2]))
inf[(ipts[1], ipts[2])] = -ipts[3]
if (-ipts[3], ipts[1], ipts[2]) in ban:
ban.remove((-ipts[3], ipts[1], ipts[2]))
elif ipts[0] == 2:
score = inf[(ipts[1], ipts[2])]
ban.add((score, ipts[1], ipts[2]))
else:
goods_ = goods.copy()
k_ = ipts[1]
ks = ipts[2:]
k_ = min(k_, sum(ks))
slts = [[] for j in range(m)]
while len(goods_) > 0 and k_ > 0:
score, tp, ids = heappop(goods_)
if (score, tp, ids) not in ban and ks[tp] > 0:
slts[tp].append(ids)
ks[tp] -= 1
k_ -= 1
for j in range(m):
if len(slts[j]) == 0:
print(-1)
else:
print(' '.join([str(it) for it in slts[j]]))