#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
ll n,k;
ld arr[300005];
pair<ld,ll> dp[300005][2];
bool check(long double lambda) {
dp[0][0] = {0, 0}, dp[0][1] = {-300000*1e9, 0};
for (int i = 1; i <= n; ++i) {
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
dp[i][1] =
max(make_pair(dp[i - 1][1].first + arr[i], dp[i - 1][1].second),
make_pair(dp[i - 1][0].first + arr[i] - lambda,
dp[i - 1][0].second + 1));
}
return max(dp[n][0], dp[n][1]).second >= k;
}
ld Aliens(){
ld l=0,r=1e9*300000;
while(r-l>=1e-4){
ld mid=(l+r)/2;
if(check(mid)){
l=mid;
}
else{
r=mid;
}
}
// cout<<dpval<<" "<<lab<<" "<<l<<"\n";
bool orz=check(l);
ld store=k;
return max(dp[n][0],dp[n][1]).first+store*l;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>arr[i];
}
ld ans=Aliens();
cout<<(ll)round(ans)<<"\n";
}
Compilation message
feast.cpp: In function 'long double Aliens()':
feast.cpp:32:6: warning: unused variable 'orz' [-Wunused-variable]
32 | bool orz=check(l);
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
254 ms |
23040 KB |
Output is correct |
2 |
Correct |
262 ms |
23508 KB |
Output is correct |
3 |
Correct |
261 ms |
23756 KB |
Output is correct |
4 |
Correct |
260 ms |
23492 KB |
Output is correct |
5 |
Correct |
263 ms |
23560 KB |
Output is correct |
6 |
Correct |
252 ms |
23072 KB |
Output is correct |
7 |
Correct |
254 ms |
22992 KB |
Output is correct |
8 |
Correct |
266 ms |
23560 KB |
Output is correct |
9 |
Correct |
255 ms |
23120 KB |
Output is correct |
10 |
Correct |
257 ms |
23352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
240 ms |
23236 KB |
Output is correct |
2 |
Correct |
249 ms |
23744 KB |
Output is correct |
3 |
Correct |
247 ms |
23136 KB |
Output is correct |
4 |
Correct |
243 ms |
23372 KB |
Output is correct |
5 |
Correct |
250 ms |
23104 KB |
Output is correct |
6 |
Correct |
242 ms |
23180 KB |
Output is correct |
7 |
Correct |
241 ms |
23796 KB |
Output is correct |
8 |
Correct |
260 ms |
23628 KB |
Output is correct |
9 |
Correct |
256 ms |
23040 KB |
Output is correct |
10 |
Correct |
246 ms |
23628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
299 ms |
23544 KB |
Output is correct |
2 |
Correct |
292 ms |
23172 KB |
Output is correct |
3 |
Correct |
292 ms |
23464 KB |
Output is correct |
4 |
Correct |
301 ms |
23252 KB |
Output is correct |
5 |
Correct |
291 ms |
23448 KB |
Output is correct |
6 |
Correct |
294 ms |
23608 KB |
Output is correct |
7 |
Correct |
291 ms |
23668 KB |
Output is correct |
8 |
Correct |
291 ms |
23476 KB |
Output is correct |
9 |
Correct |
299 ms |
23768 KB |
Output is correct |
10 |
Correct |
302 ms |
23700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 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 |
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 |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 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 |
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 |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
254 ms |
23040 KB |
Output is correct |
2 |
Correct |
262 ms |
23508 KB |
Output is correct |
3 |
Correct |
261 ms |
23756 KB |
Output is correct |
4 |
Correct |
260 ms |
23492 KB |
Output is correct |
5 |
Correct |
263 ms |
23560 KB |
Output is correct |
6 |
Correct |
252 ms |
23072 KB |
Output is correct |
7 |
Correct |
254 ms |
22992 KB |
Output is correct |
8 |
Correct |
266 ms |
23560 KB |
Output is correct |
9 |
Correct |
255 ms |
23120 KB |
Output is correct |
10 |
Correct |
257 ms |
23352 KB |
Output is correct |
11 |
Correct |
240 ms |
23236 KB |
Output is correct |
12 |
Correct |
249 ms |
23744 KB |
Output is correct |
13 |
Correct |
247 ms |
23136 KB |
Output is correct |
14 |
Correct |
243 ms |
23372 KB |
Output is correct |
15 |
Correct |
250 ms |
23104 KB |
Output is correct |
16 |
Correct |
242 ms |
23180 KB |
Output is correct |
17 |
Correct |
241 ms |
23796 KB |
Output is correct |
18 |
Correct |
260 ms |
23628 KB |
Output is correct |
19 |
Correct |
256 ms |
23040 KB |
Output is correct |
20 |
Correct |
246 ms |
23628 KB |
Output is correct |
21 |
Correct |
299 ms |
23544 KB |
Output is correct |
22 |
Correct |
292 ms |
23172 KB |
Output is correct |
23 |
Correct |
292 ms |
23464 KB |
Output is correct |
24 |
Correct |
301 ms |
23252 KB |
Output is correct |
25 |
Correct |
291 ms |
23448 KB |
Output is correct |
26 |
Correct |
294 ms |
23608 KB |
Output is correct |
27 |
Correct |
291 ms |
23668 KB |
Output is correct |
28 |
Correct |
291 ms |
23476 KB |
Output is correct |
29 |
Correct |
299 ms |
23768 KB |
Output is correct |
30 |
Correct |
302 ms |
23700 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
0 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 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 |
340 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 |
468 KB |
Output is correct |
52 |
Correct |
2 ms |
468 KB |
Output is correct |
53 |
Correct |
2 ms |
468 KB |
Output is correct |
54 |
Correct |
2 ms |
468 KB |
Output is correct |
55 |
Correct |
2 ms |
468 KB |
Output is correct |
56 |
Correct |
2 ms |
468 KB |
Output is correct |
57 |
Correct |
2 ms |
468 KB |
Output is correct |
58 |
Correct |
2 ms |
468 KB |
Output is correct |
59 |
Correct |
2 ms |
468 KB |
Output is correct |
60 |
Correct |
2 ms |
468 KB |
Output is correct |
61 |
Correct |
357 ms |
23212 KB |
Output is correct |
62 |
Correct |
359 ms |
23756 KB |
Output is correct |
63 |
Correct |
317 ms |
26132 KB |
Output is correct |
64 |
Correct |
371 ms |
26656 KB |
Output is correct |
65 |
Correct |
373 ms |
26572 KB |
Output is correct |
66 |
Correct |
370 ms |
26564 KB |
Output is correct |
67 |
Correct |
366 ms |
26220 KB |
Output is correct |
68 |
Correct |
295 ms |
26604 KB |
Output is correct |
69 |
Correct |
289 ms |
26152 KB |
Output is correct |
70 |
Correct |
286 ms |
25952 KB |
Output is correct |