-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbadmilk.py
More file actions
55 lines (47 loc) · 1.18 KB
/
badmilk.py
File metadata and controls
55 lines (47 loc) · 1.18 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
with open("badmilk.in","r") as f_in:
N, M, D, S = map(int,f_in.readline().strip("\n").split())
drink = []
for _ in range(D):
p, m, t = map(int,f_in.readline().strip("\n").split())
drink.append([p,m,t])
sick = []
for _ in range(S):
p, t = map(int,f_in.readline().strip("\n").split())
sick.append([p,t])
dict1 = {}
for x in sick:
p1 = x[0]
t1 = x[1]
for y in drink:
p2 = y[0]
m2 = y[1]
t2 = y[2]
if p1 != p2:
continue
if t2 >= t1:
continue
if p1 not in dict1:
dict1[p1] = [m2]
else:
t = dict1[p1]
t.append(m2)
dict1[p1] = t
bad_milk = set() #set
first = True
for i, v in dict1.items():
if first:
bad_milk = set(v)
first = False
else:
bad_milk = bad_milk & set(v)
print(set(v), bad_milk)
max = 0
for x in bad_milk:
ppl = set()
for y in drink:
if y[1] == x:
ppl.add(y[0])
if len(ppl) > max:
max = len(ppl)
with open("badmilk.out", "w") as f_out:
f_out.write(str(max) + "\n")