Hey Guys,
I am trying to solve this problem [contest:260][problem:A](https://mirror.codeforces.com/contest/455/problem/A) tagged DP. I am getting runtime error for my submission in case of larger inputs.
n =int(input())
arr = [int(x) for x in input().split()]
freq = [0]*(n + 1)
for i in arr:
freq[i] = freq[i] + 1
dic = {}
def dp(a):
if a in dic:
return dic[a]
if(a==0):
return 0
if(a==1):
return freq[1]
res = max(dp(a-1), dp(a-2)+a*freq[a])
dic[a] = res
return res
print(dp(n))
Can anyone please explain what I am doing wrong, I am a beginner. Any help will be appreciated.