对了2个点,但一分没得
照例用dp与高精(后者想了100000000次才想出来)
上代码(悬赏关注)
#include<bits/stdc++.h>
#define fro for
using namespace std;
typedef unsigned long long ull;
const static int N=1e6+5;
const static unsigned long long BASE=1e18;
int n,p;
ull a[N];
ull f[N];
bool cmp(ull a[2],ull b[2]){
if(a[1]==b[1])return a[0]<b[0];
else return a[1]<b[1];
}
int main(){
cin>>n>>p;
fro(int i=1;i<=n;i++)cin>>a[i];
f[1]=a[1];
ull maxn=f[1];
ull res=f[1];
fro(int i=2;i<=n;i++){
maxn=max(maxn+a[i],a[i]);
res=max(maxn,res);
f[i]=res;
}
ull maxs[2]={f[1]};
ull g[2]={f[1]};
ull maxx[2]={f[1]+f[1]};
fro(int i=2;i<n;i++){
ull res[2]={0,0};
res[0]=f[i-1]+g[0];
res[1]=g[1];
res[1]+=res[0]/BASE;
res[0]=res[0]%BASE;
if(cmp(maxx,res))maxx[1]=res[1],maxx[0]=res[0];
g[1]=maxx[1];
g[0]=maxx[0];
if(cmp(maxs,g))maxs[1]=g[1],maxs[0]=g[0];
}
cout<<(maxs[1]%p*(BASE%p)+maxs[0]%p)%p;
return 0;
}