Hi everyone, i have started learning python . So i want to know what is the bug in my program: The same code 204659837 in c++ works fine, but in python its not even working on sample tests. Please enlighten me. My python code:
INF=2e18
def dfs(idx,cnt)->int:
if(idx>=n):
if(cnt!=3):
return -INF
return 0
ans=dp[idx][cnt]
if(vis[idx][cnt]):
return ans
vis[idx][cnt]=1
ans=0
ans=max(ans,dfs(idx+1,cnt))
if(cnt<3):
if(cnt==0):
ans=max(ans,dfs(idx+1,cnt+1)+(a[idx]+idx+1));
elif(cnt==1):
ans=max(ans,dfs(idx+1,cnt+1)+a[idx]);
elif(cnt==2):
ans=max(ans,dfs(idx+1,cnt+1)+a[idx]-(idx+1));
dp[idx][cnt]=ans
return ans
for i in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
dp=[[-1]*5 for i in range(n+5)]
vis=[[0]*5 for i in range(n+5)]
print(dfs(0,0))