# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
731486 |
2023-04-27T13:22:37 Z |
mohav48173 |
Feast (NOI19_feast) |
C++14 |
|
160 ms |
5064 KB |
#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=1e15;
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
121 ms |
4844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
4824 KB |
Output is correct |
2 |
Correct |
78 ms |
4928 KB |
Output is correct |
3 |
Correct |
79 ms |
4776 KB |
Output is correct |
4 |
Incorrect |
78 ms |
4908 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
4876 KB |
Output is correct |
2 |
Correct |
151 ms |
4812 KB |
Output is correct |
3 |
Correct |
155 ms |
4984 KB |
Output is correct |
4 |
Correct |
157 ms |
4948 KB |
Output is correct |
5 |
Correct |
155 ms |
4820 KB |
Output is correct |
6 |
Correct |
152 ms |
4940 KB |
Output is correct |
7 |
Correct |
160 ms |
4900 KB |
Output is correct |
8 |
Correct |
155 ms |
4896 KB |
Output is correct |
9 |
Correct |
155 ms |
4980 KB |
Output is correct |
10 |
Correct |
157 ms |
5064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
121 ms |
4844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |