-
Notifications
You must be signed in to change notification settings - Fork 6
/
administrativeproblems.py
20 lines (20 loc) · 1.01 KB
/
administrativeproblems.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import sys; input = sys.stdin.readline
for _ in range(int(input())):
n, m = map(int, input().split())
price = {}; pickup = {}; rate = {}; using = {}; consistent = {}; cost = {}
for _ in range(n): N, *r = input().split(); price[N], pickup[N], rate[N] = map(int, r)
for _ in range(m):
_, p, e, r = input().split()
if p not in cost: using[p], consistent[p], cost[p] = None, True, 0
if e == 'p':
if using[p] != None: consistent[p] = False
if consistent[p]: c = r.strip(); cost[p] += pickup[c]; using[p] = c
elif e == 'r':
if using[p] == None: consistent[p] = False
if consistent[p]: cost[p] += int(r)*rate[using[p]]; using[p] = None
else:
if using[p] == None: consistent[p] = False
if consistent[p]: cost[p] += (int(r)*price[using[p]]+99)//100
for p in using:
if using[p] != None: consistent[p] = False
for p in sorted(cost): print(p, cost[p] if consistent[p] else 'INCONSISTENT')