This game is relatively simple, each person's goal is only to let their own points more. So direct DP DP Request:
Set fi,0 f_{i,0} to represent the first pick from I I, the best value of the upper tempo. fi,1 f_{i,1} is the optimal value of a.
Obviously there are fi,0=max{aj+fj+1,1} f_{i,0}=max\{a_j+f_{j+1,1}\}, fi,1=fpos,0 f_{i,1}=f_{pos,0}. Pos POS indicates where the fi,0 f_{i,0} is transferred from.
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=700015;
typedef long long LL;
int N,A[MAXN];
LL f[maxn][2];
int main () {
freopen ("bzoj1783.in", "R", stdin);
Freopen ("Bzoj1783.out", "w", stdout);
scanf ("%d", &n);
for (int i=1;i<=n;i++) scanf ("%d", &a[i]);
int pos=n+1;
for (int i=n;i>=1;i--) {
if (a[i]+f[i+1][1]>=a[pos]+f[pos+1][1]) pos=i;
F[I][0]=A[POS]+F[POS+1][1];
F[I][1]=F[POS+1][0];
}
printf ("%lld%lld\n", f[1][0],f[1][1]);
return 0;