#include<bits/stdc++.h>
using namespace std;
int n,k;
long long a[400000];
long long m[400000];
long long mincnt=0;
long long score=0;
long long get(int ind) {
if(ind<0)return 0;
else return m[ind];
}
void calc(long long lam) {
long long bestscore=0;
long long bestcnt=0;
long long bestnxt=-lam;
long long nxtcnt=0;
for(int i=0;i<n;i++) {
if(bestscore-lam-get(i-1)>bestnxt ||
(bestscore-lam-get(i-1)==bestnxt && nxtcnt>bestcnt)) {
bestnxt=bestscore-get(i-1)-lam;
nxtcnt=bestcnt;
}
if(bestnxt+get(i)>bestscore || (bestnxt+get(i)==bestscore && nxtcnt+1<bestcnt)) {
bestscore=bestnxt+get(i);
bestcnt=nxtcnt+1;
}
}
mincnt=bestcnt;
score=bestscore;
}
int main() {
cin>>n>>k;
for(int i=0;i<n;i++)cin>>a[i];
m[0]=a[0];for(int i=1;i<n;i++)m[i]=m[i-1]+a[i];
long long l=0,r=1e16;
while(l+1<r) {
long long mid=(l+r)/2;
calc(mid);
if(mincnt<=k)r=mid;
else l=mid;
}
calc(r);
cout<<score+k*r<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
127 ms |
7608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
5888 KB |
Output is correct |
2 |
Correct |
78 ms |
6020 KB |
Output is correct |
3 |
Correct |
80 ms |
6036 KB |
Output is correct |
4 |
Incorrect |
78 ms |
5932 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
7968 KB |
Output is correct |
2 |
Correct |
157 ms |
7752 KB |
Output is correct |
3 |
Correct |
160 ms |
8000 KB |
Output is correct |
4 |
Correct |
159 ms |
7764 KB |
Output is correct |
5 |
Correct |
161 ms |
8084 KB |
Output is correct |
6 |
Correct |
155 ms |
7884 KB |
Output is correct |
7 |
Correct |
157 ms |
7980 KB |
Output is correct |
8 |
Correct |
156 ms |
7832 KB |
Output is correct |
9 |
Correct |
156 ms |
7976 KB |
Output is correct |
10 |
Correct |
155 ms |
7924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
127 ms |
7608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |