3 solutions

  • 0
    @ 2025-9-27 11:43:57

    #include<bits/stdc++.h> using namespace std; long long n,p,f[1000010],s,maxs=-2e18,x,res,sc; int main() { cin>>n>>p; for(int i=1;i<=n;i++) { cin>>x; s=max(s,0ll)+x; maxs=max(s,maxs); f[i]=maxs; } res=f[1],sc=res*2; for(int i=2;i<=n;i++) { res=max(res,sc)%p; sc+=max(0ll,f[i])%p; } cout<<res%p; return 0; }

    Information

    ID
    443
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    9
    Tags
    # Submissions
    18
    Accepted
    3
    Uploaded By