-
Notifications
You must be signed in to change notification settings - Fork 0
/
DCEPC501.cpp
53 lines (48 loc) · 962 Bytes
/
DCEPC501.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define lld long long int
lld n,arr[100001];
lld dp[100001];
//-4%3=-1
lld max(lld a,lld b)
{
if(a>b)
return a;
return b;
}
lld fun(int i)
{
if(i>n)
return 0LL;
if(dp[i]!=-1)
return dp[i];
else
{
lld a1=0,a2=0,a3=0;
if(i<=n)
a1=arr[i]+fun(i+2*1);
if(i+1<=n)
a2=arr[i]+arr[i+1]+fun(i+2*2);
if(i+2<=n)
a3=arr[i]+arr[i+1]+arr[i+2]+fun(i+2*3);
return dp[i]=max(a1,max(a2,a3));
}
}
int main() {
// your code goes here
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lld t;
cin>>t;
while(t--)
{
cin>>n;
memset(dp,-1,sizeof(dp));
for(int i=1;i<=n;i++)
cin>>arr[i];
cout<<fun(1)<<"\n";
}
}