# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1426084215 14400 # Node ID cd24a8027d5fe7e6ae864a1cbc391b087c00345b # Parent 14c8b6dad88a07db55bfd884293fbd4e1eaf863b parseinput: skip impossible and unprofitable machines diff --git a/optim.py b/optim.py --- a/optim.py +++ b/optim.py @@ -20,9 +20,17 @@ for i in range(0, N): machine = Machine(*[int(x) for x in f.readline().split()], maxprofit = None) + # Maximum profit possible from each machine maxprofit = ((case.days - machine.day)*machine.profit - machine.buy + machine.sell) + + # Skip machines that can only give a loss. This + # includes machines that can only be bought after + # case.days. + if maxprofit < 0: + continue + machine = machine._replace(maxprofit = maxprofit) case.machines.append(machine)