# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
731515 |
2023-04-27T13:43:57 Z |
mohav48173 |
Feast (NOI19_feast) |
C++14 |
|
275 ms |
6032 KB |
#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-6)) {
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
5776 KB |
Output is correct |
2 |
Correct |
92 ms |
5704 KB |
Output is correct |
3 |
Correct |
91 ms |
5716 KB |
Output is correct |
4 |
Correct |
88 ms |
5708 KB |
Output is correct |
5 |
Correct |
87 ms |
5692 KB |
Output is correct |
6 |
Correct |
83 ms |
5636 KB |
Output is correct |
7 |
Correct |
82 ms |
5632 KB |
Output is correct |
8 |
Correct |
86 ms |
5788 KB |
Output is correct |
9 |
Correct |
84 ms |
5560 KB |
Output is correct |
10 |
Correct |
95 ms |
5624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
5832 KB |
Output is correct |
2 |
Correct |
74 ms |
6028 KB |
Output is correct |
3 |
Correct |
92 ms |
5912 KB |
Output is correct |
4 |
Correct |
84 ms |
5892 KB |
Output is correct |
5 |
Correct |
102 ms |
5636 KB |
Output is correct |
6 |
Correct |
71 ms |
5656 KB |
Output is correct |
7 |
Correct |
74 ms |
5732 KB |
Output is correct |
8 |
Correct |
86 ms |
5748 KB |
Output is correct |
9 |
Correct |
87 ms |
5580 KB |
Output is correct |
10 |
Correct |
75 ms |
5652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
146 ms |
5868 KB |
Output is correct |
2 |
Correct |
155 ms |
5932 KB |
Output is correct |
3 |
Correct |
144 ms |
5968 KB |
Output is correct |
4 |
Correct |
147 ms |
5836 KB |
Output is correct |
5 |
Correct |
150 ms |
6008 KB |
Output is correct |
6 |
Correct |
144 ms |
5892 KB |
Output is correct |
7 |
Correct |
145 ms |
5964 KB |
Output is correct |
8 |
Correct |
144 ms |
5964 KB |
Output is correct |
9 |
Correct |
156 ms |
6032 KB |
Output is correct |
10 |
Correct |
158 ms |
6004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 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 |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 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 |
332 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 |
368 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 |
344 KB |
Output is correct |
26 |
Correct |
2 ms |
364 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 |
336 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
5776 KB |
Output is correct |
2 |
Correct |
92 ms |
5704 KB |
Output is correct |
3 |
Correct |
91 ms |
5716 KB |
Output is correct |
4 |
Correct |
88 ms |
5708 KB |
Output is correct |
5 |
Correct |
87 ms |
5692 KB |
Output is correct |
6 |
Correct |
83 ms |
5636 KB |
Output is correct |
7 |
Correct |
82 ms |
5632 KB |
Output is correct |
8 |
Correct |
86 ms |
5788 KB |
Output is correct |
9 |
Correct |
84 ms |
5560 KB |
Output is correct |
10 |
Correct |
95 ms |
5624 KB |
Output is correct |
11 |
Correct |
87 ms |
5832 KB |
Output is correct |
12 |
Correct |
74 ms |
6028 KB |
Output is correct |
13 |
Correct |
92 ms |
5912 KB |
Output is correct |
14 |
Correct |
84 ms |
5892 KB |
Output is correct |
15 |
Correct |
102 ms |
5636 KB |
Output is correct |
16 |
Correct |
71 ms |
5656 KB |
Output is correct |
17 |
Correct |
74 ms |
5732 KB |
Output is correct |
18 |
Correct |
86 ms |
5748 KB |
Output is correct |
19 |
Correct |
87 ms |
5580 KB |
Output is correct |
20 |
Correct |
75 ms |
5652 KB |
Output is correct |
21 |
Correct |
146 ms |
5868 KB |
Output is correct |
22 |
Correct |
155 ms |
5932 KB |
Output is correct |
23 |
Correct |
144 ms |
5968 KB |
Output is correct |
24 |
Correct |
147 ms |
5836 KB |
Output is correct |
25 |
Correct |
150 ms |
6008 KB |
Output is correct |
26 |
Correct |
144 ms |
5892 KB |
Output is correct |
27 |
Correct |
145 ms |
5964 KB |
Output is correct |
28 |
Correct |
144 ms |
5964 KB |
Output is correct |
29 |
Correct |
156 ms |
6032 KB |
Output is correct |
30 |
Correct |
158 ms |
6004 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
2 ms |
340 KB |
Output is correct |
52 |
Correct |
2 ms |
368 KB |
Output is correct |
53 |
Correct |
2 ms |
340 KB |
Output is correct |
54 |
Correct |
2 ms |
340 KB |
Output is correct |
55 |
Correct |
2 ms |
344 KB |
Output is correct |
56 |
Correct |
2 ms |
364 KB |
Output is correct |
57 |
Correct |
2 ms |
340 KB |
Output is correct |
58 |
Correct |
2 ms |
340 KB |
Output is correct |
59 |
Correct |
2 ms |
336 KB |
Output is correct |
60 |
Correct |
2 ms |
340 KB |
Output is correct |
61 |
Correct |
250 ms |
5784 KB |
Output is correct |
62 |
Correct |
241 ms |
5940 KB |
Output is correct |
63 |
Correct |
184 ms |
5800 KB |
Output is correct |
64 |
Correct |
250 ms |
5856 KB |
Output is correct |
65 |
Correct |
275 ms |
5776 KB |
Output is correct |
66 |
Correct |
253 ms |
5748 KB |
Output is correct |
67 |
Correct |
254 ms |
5776 KB |
Output is correct |
68 |
Correct |
142 ms |
5868 KB |
Output is correct |
69 |
Correct |
147 ms |
5776 KB |
Output is correct |
70 |
Correct |
136 ms |
5640 KB |
Output is correct |