-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathplay-game.cpp
More file actions
46 lines (46 loc) · 736 Bytes
/
play-game.cpp
File metadata and controls
46 lines (46 loc) · 736 Bytes
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
//https://www.hackerrank.com/challenges/play-game
//mandeep singh @msdeep14
#include<iostream>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int main()
{
ll int t,n;
ll int score[100001];
ll int sum[100001];
ll int best[100001];
cin>>t;
while(t--)
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>score[i];
}
for(int i=1;i<=n+1;i++)
{
sum[i]=0;
best[i]=0;
}
//memset(sum,0,n+1);
//memset(best,0,n+1);
for(int i=n;i>=1;i--)
{
sum[i]=score[i] + sum[i+1];
}
best[n]=sum[n];
best[n-1]=sum[n-1];
best[n-2]=sum[n-2];
for(int i=n-3;i>=1;i--)
{
for(int j=1;j<=3;j++)
{
best[i]=max(best[i],sum[i]-best[i+j]);
}
}
cout<<best[1]<<endl;
}
return 0;
}