Runtime error in question "boredom" (455A)

Revision en1, by vasanthaganesh, 2016-01-20 16:10:42

link to the question: http://codeforces.net/contest/455/problem/A

Source-code:

from collections import Counter import sys sys.setrecursionlimit(100000000)

raw_input() a = map(int, raw_input().split())

f = Counter(a)

memo = {} def dp(i): if i in memo: return memo[i] elif i <= 0: temp = 0 else: if i not in f: temp = max(dp(i-1), dp(i-2)) else: temp = i*f[i] + max(dp(i-2), dp(i-3)) memo[i] = temp return temp

print max(dp(max(a)), dp(max(a) — 1))

Tags dynamic programming, runtime error

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English vasanthaganesh 2016-01-20 17:42:55 216 updated blog text
en2 English vasanthaganesh 2016-01-20 16:32:56 424 code was not displayed properly, so i linked the submission
en1 English vasanthaganesh 2016-01-20 16:10:42 546 Initial revision (published)