# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
440014 |
2021-07-01T12:20:50 Z |
dongliu0426 |
Feast (NOI19_feast) |
C++14 |
|
717 ms |
20416 KB |
#include <bits/stdc++.h>
using namespace std;
#define N 300000
#define INF ((long long) 300000 * 1000000000)
int n, k, a[N + 1];
pair<long double, int> dp[N + 1][2];
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i)
scanf("%d", a + i);
auto check = [&](long double penalty) {
dp[0][0] = {0, 0}, dp[0][1] = {-INF, 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 + a[i], dp[i - 1][1].second),
make_pair(dp[i - 1][0].first + a[i] - penalty, dp[i - 1][0].second + 1));
}
return max(dp[n][0], dp[n][1]).second >= k;
};
long double lower = 0, upper = INF;
for (int it = 0; it < 100; ++it) {
long double mid = (lower + upper) / 2;
if (check(mid)) {
lower = mid;
} else {
upper = mid;
}
}
long double penalty = lower;
check(penalty);
printf("%lld\n", (long long) round(penalty * k + max(dp[n][0], dp[n][1]).first));
}
Compilation message
feast.cpp: In function 'int main()':
feast.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | scanf("%d%d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~
feast.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d", a + i);
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
480 ms |
19616 KB |
Output is correct |
2 |
Correct |
487 ms |
19988 KB |
Output is correct |
3 |
Correct |
493 ms |
20416 KB |
Output is correct |
4 |
Correct |
481 ms |
20136 KB |
Output is correct |
5 |
Correct |
478 ms |
19968 KB |
Output is correct |
6 |
Correct |
459 ms |
19632 KB |
Output is correct |
7 |
Correct |
460 ms |
19628 KB |
Output is correct |
8 |
Correct |
473 ms |
20028 KB |
Output is correct |
9 |
Correct |
515 ms |
19780 KB |
Output is correct |
10 |
Correct |
475 ms |
19876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
451 ms |
19756 KB |
Output is correct |
2 |
Correct |
488 ms |
20192 KB |
Output is correct |
3 |
Correct |
435 ms |
19732 KB |
Output is correct |
4 |
Correct |
472 ms |
19904 KB |
Output is correct |
5 |
Correct |
472 ms |
19648 KB |
Output is correct |
6 |
Correct |
469 ms |
19740 KB |
Output is correct |
7 |
Correct |
518 ms |
20232 KB |
Output is correct |
8 |
Correct |
496 ms |
20036 KB |
Output is correct |
9 |
Correct |
492 ms |
19584 KB |
Output is correct |
10 |
Correct |
467 ms |
20096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
548 ms |
20016 KB |
Output is correct |
2 |
Correct |
528 ms |
19756 KB |
Output is correct |
3 |
Correct |
519 ms |
19952 KB |
Output is correct |
4 |
Correct |
553 ms |
19768 KB |
Output is correct |
5 |
Correct |
526 ms |
19872 KB |
Output is correct |
6 |
Correct |
545 ms |
20164 KB |
Output is correct |
7 |
Correct |
514 ms |
20140 KB |
Output is correct |
8 |
Correct |
514 ms |
19908 KB |
Output is correct |
9 |
Correct |
537 ms |
20216 KB |
Output is correct |
10 |
Correct |
573 ms |
20152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
5 ms |
332 KB |
Output is correct |
22 |
Correct |
5 ms |
428 KB |
Output is correct |
23 |
Correct |
5 ms |
332 KB |
Output is correct |
24 |
Correct |
4 ms |
332 KB |
Output is correct |
25 |
Correct |
5 ms |
332 KB |
Output is correct |
26 |
Correct |
4 ms |
332 KB |
Output is correct |
27 |
Correct |
5 ms |
332 KB |
Output is correct |
28 |
Correct |
4 ms |
332 KB |
Output is correct |
29 |
Correct |
4 ms |
332 KB |
Output is correct |
30 |
Correct |
4 ms |
432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
480 ms |
19616 KB |
Output is correct |
2 |
Correct |
487 ms |
19988 KB |
Output is correct |
3 |
Correct |
493 ms |
20416 KB |
Output is correct |
4 |
Correct |
481 ms |
20136 KB |
Output is correct |
5 |
Correct |
478 ms |
19968 KB |
Output is correct |
6 |
Correct |
459 ms |
19632 KB |
Output is correct |
7 |
Correct |
460 ms |
19628 KB |
Output is correct |
8 |
Correct |
473 ms |
20028 KB |
Output is correct |
9 |
Correct |
515 ms |
19780 KB |
Output is correct |
10 |
Correct |
475 ms |
19876 KB |
Output is correct |
11 |
Correct |
451 ms |
19756 KB |
Output is correct |
12 |
Correct |
488 ms |
20192 KB |
Output is correct |
13 |
Correct |
435 ms |
19732 KB |
Output is correct |
14 |
Correct |
472 ms |
19904 KB |
Output is correct |
15 |
Correct |
472 ms |
19648 KB |
Output is correct |
16 |
Correct |
469 ms |
19740 KB |
Output is correct |
17 |
Correct |
518 ms |
20232 KB |
Output is correct |
18 |
Correct |
496 ms |
20036 KB |
Output is correct |
19 |
Correct |
492 ms |
19584 KB |
Output is correct |
20 |
Correct |
467 ms |
20096 KB |
Output is correct |
21 |
Correct |
548 ms |
20016 KB |
Output is correct |
22 |
Correct |
528 ms |
19756 KB |
Output is correct |
23 |
Correct |
519 ms |
19952 KB |
Output is correct |
24 |
Correct |
553 ms |
19768 KB |
Output is correct |
25 |
Correct |
526 ms |
19872 KB |
Output is correct |
26 |
Correct |
545 ms |
20164 KB |
Output is correct |
27 |
Correct |
514 ms |
20140 KB |
Output is correct |
28 |
Correct |
514 ms |
19908 KB |
Output is correct |
29 |
Correct |
537 ms |
20216 KB |
Output is correct |
30 |
Correct |
573 ms |
20152 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
1 ms |
204 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Correct |
1 ms |
204 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
1 ms |
204 KB |
Output is correct |
45 |
Correct |
1 ms |
204 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
1 ms |
204 KB |
Output is correct |
50 |
Correct |
1 ms |
204 KB |
Output is correct |
51 |
Correct |
5 ms |
332 KB |
Output is correct |
52 |
Correct |
5 ms |
428 KB |
Output is correct |
53 |
Correct |
5 ms |
332 KB |
Output is correct |
54 |
Correct |
4 ms |
332 KB |
Output is correct |
55 |
Correct |
5 ms |
332 KB |
Output is correct |
56 |
Correct |
4 ms |
332 KB |
Output is correct |
57 |
Correct |
5 ms |
332 KB |
Output is correct |
58 |
Correct |
4 ms |
332 KB |
Output is correct |
59 |
Correct |
4 ms |
332 KB |
Output is correct |
60 |
Correct |
4 ms |
432 KB |
Output is correct |
61 |
Correct |
716 ms |
19736 KB |
Output is correct |
62 |
Correct |
682 ms |
20220 KB |
Output is correct |
63 |
Correct |
584 ms |
19680 KB |
Output is correct |
64 |
Correct |
693 ms |
20076 KB |
Output is correct |
65 |
Correct |
702 ms |
20064 KB |
Output is correct |
66 |
Correct |
717 ms |
20016 KB |
Output is correct |
67 |
Correct |
686 ms |
19652 KB |
Output is correct |
68 |
Correct |
523 ms |
20088 KB |
Output is correct |
69 |
Correct |
529 ms |
19736 KB |
Output is correct |
70 |
Correct |
534 ms |
19600 KB |
Output is correct |