You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
596 B
29 lines
596 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
typedef __int128 LL;
|
|
const int N = 1000010;
|
|
int n, p;
|
|
LL f[N];
|
|
LL max(LL a, LL b) {
|
|
if (a >= b) return a;
|
|
return b;
|
|
}
|
|
int main() {
|
|
cin >> n >> p;
|
|
LL s = 0, mx = -1e36;
|
|
for (int i = 1; i <= n; i++) {
|
|
int x;
|
|
cin >> x;
|
|
s = max(s, 0) + x;
|
|
mx = max(mx, s);
|
|
f[i] = mx;
|
|
}
|
|
LL res = f[1], score = f[1] * 2;
|
|
for (int i = 2; i <= n; i++) {
|
|
res = max(res, score);
|
|
if (f[i] > 0) score += f[i];
|
|
}
|
|
printf("%lld\n", res % p);
|
|
return 0;
|
|
} |