Created
April 25, 2019 12:30
-
-
Save IvanaGyro/e67a616b654ce3a7fc33efcc3c665888 to your computer and use it in GitHub Desktop.
The wrong answer to the second problem of 2019 Kick Start round B
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from operator import itemgetter | |
def eat(stones): | |
max_e = {} | |
stones.sort(key=itemgetter(2), reverse=True) | |
def dp(time, i): | |
if i == len(stones): | |
return 0 | |
if (time, i) not in max_e: | |
max_e[(time, i)] = max( | |
dp(time, i + 1), | |
dp(time + stones[i][0], i + 1) + max( | |
stones[i][1] - time*stones[i][2], | |
0, | |
), | |
) | |
return max_e[(time, i)] | |
return dp(0, 0) | |
task = int(input()) | |
for case in range(task): | |
n = int(input()) | |
stones = [tuple(int(s) for s in input().split(' ')) for _ in range(n)] | |
ans = eat(stones) | |
print('Case: #{}: {}'.format(case, ans)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am able to write JS, so JS is fine. If the stones are sorted by L and E in descending, the logic of your method seems correct. But I still cannot pass the first test set after I changed the function,
eat
, to :