70pts求调
查看原帖
70pts求调
1285357
jinminghao楼主2024/8/19 13:51
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e6+10;
__int128 a[N],f[N];//f表示特征值 
__int128 read(){
	__int128 x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
void write(__int128 x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
int main(){
	int n,p;
	scanf("%d%d",&n,&p);
	for(int i=1;i<=n;i++){
		a[i]=read();
		f[i]=max(f[i-1]+a[i],a[i]);
	}
	__int128 sum=f[1],res=f[1],maxn=f[1],ans=f[1];
	for(int i=2;i<=n;i++){
		res=sum+maxn;
		ans=max(ans,res);
		sum=max(sum,res);
		__int128 t=f[i];
		maxn=max(maxn,t);
	}
	write(ans%p);
	return 0;
}
2024/8/19 13:51
加载中...