We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e53d34d commit 2184e8eCopy full SHA for 2184e8e
DP/Sterling_thief.py
@@ -0,0 +1,9 @@
1
+for _ in range(int(input())):
2
+ n = int(input())
3
+ arr = list(map(int,input().split()))
4
+ if n==1:print(arr[0])
5
+ elif n==2:print(max(arr[0],arr[1]))
6
+ else:
7
+ dp = [arr[0],max(arr[0],arr[1])]
8
+ for i in range(2,n):dp.append(max(dp[i-1],arr[i]+dp[i-2]))
9
+ print(dp[n-1])
0 commit comments