#include<bits/stdc++.h>
using namespace std;
int n,k;
long long a[400000];
long long m[400000];
long long mincnt=0;
long double score=0;
long double get(int ind) {
if(ind<0)return 0;
else return m[ind];
}
void calc(long double lam) {
long double bestscore=0;
long long bestcnt=0;
long double 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() {
ios_base::sync_with_stdio(0);cin.tie(0);
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 double l=0,r=1e18;
while((r-l)>(long double)(1e-7)) {
long double mid=(l+r)/2.0;
calc(mid);
if(mincnt<k)r=mid;
else l=mid;
}
calc(r);
cout<<(long long)(round(score+k*r))<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
4780 KB |
Output is correct |
2 |
Correct |
100 ms |
4952 KB |
Output is correct |
3 |
Correct |
89 ms |
4936 KB |
Output is correct |
4 |
Correct |
98 ms |
4940 KB |
Output is correct |
5 |
Correct |
100 ms |
4952 KB |
Output is correct |
6 |
Correct |
89 ms |
4864 KB |
Output is correct |
7 |
Correct |
88 ms |
4868 KB |
Output is correct |
8 |
Correct |
89 ms |
5064 KB |
Output is correct |
9 |
Correct |
93 ms |
4848 KB |
Output is correct |
10 |
Correct |
123 ms |
4924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
4904 KB |
Output is correct |
2 |
Correct |
74 ms |
4996 KB |
Output is correct |
3 |
Correct |
77 ms |
4892 KB |
Output is correct |
4 |
Correct |
95 ms |
4932 KB |
Output is correct |
5 |
Execution timed out |
1074 ms |
4836 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
4956 KB |
Output is correct |
2 |
Correct |
162 ms |
4904 KB |
Output is correct |
3 |
Correct |
163 ms |
4948 KB |
Output is correct |
4 |
Correct |
147 ms |
5008 KB |
Output is correct |
5 |
Correct |
146 ms |
4940 KB |
Output is correct |
6 |
Correct |
183 ms |
4972 KB |
Output is correct |
7 |
Correct |
160 ms |
4988 KB |
Output is correct |
8 |
Correct |
152 ms |
4944 KB |
Output is correct |
9 |
Correct |
168 ms |
5008 KB |
Output is correct |
10 |
Correct |
154 ms |
5080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
4780 KB |
Output is correct |
2 |
Correct |
100 ms |
4952 KB |
Output is correct |
3 |
Correct |
89 ms |
4936 KB |
Output is correct |
4 |
Correct |
98 ms |
4940 KB |
Output is correct |
5 |
Correct |
100 ms |
4952 KB |
Output is correct |
6 |
Correct |
89 ms |
4864 KB |
Output is correct |
7 |
Correct |
88 ms |
4868 KB |
Output is correct |
8 |
Correct |
89 ms |
5064 KB |
Output is correct |
9 |
Correct |
93 ms |
4848 KB |
Output is correct |
10 |
Correct |
123 ms |
4924 KB |
Output is correct |
11 |
Correct |
90 ms |
4904 KB |
Output is correct |
12 |
Correct |
74 ms |
4996 KB |
Output is correct |
13 |
Correct |
77 ms |
4892 KB |
Output is correct |
14 |
Correct |
95 ms |
4932 KB |
Output is correct |
15 |
Execution timed out |
1074 ms |
4836 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |