EPS/2024/04/29-04-24-Partiel/b1.py

18 lines
590 B
Python
Raw Normal View History

2024-05-06 15:21:59 +02:00
R, r = map(int, input().split())
Ri = [int(input()) for _ in range(R)]
recettes = []
for i in range(r):
r_in, r_out = map(int, input().split())
rec = [tuple(map(int, input().split())) for _ in range(r_in)]
if r_out != 0:
recettes.append((r_in, r_out, rec))
perfect = 0
recettes.sort(key=lambda x:sum((r_[1] for r_ in x[2]))/x[0])TEMPS
for r_in, r_out, rec in recettes: # need to use the best recipes first !
produced = min([int(Ri[r_[0]-1]/r_[1]) for r_ in rec])
perfect += r_out*produced
for r_ in rec:
Ri[r_[0]-1] -= produced*r_[1]
print(perfect)