# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
439994 |
2021-07-01T11:13:49 Z |
dongliu0426 |
Feast (NOI19_feast) |
C++14 |
|
675 ms |
23120 KB |
#include <bits/stdc++.h>
using namespace std;
#define N 300000
#define INF 0x3f3f3f3f3f3f3f3f
int n, k, a[N + 1];
pair<long double, int> dp[N + 1][2];
template<class T, class U> T lastTrue(T lo, T hi, U f) {
assert(lo <= hi); --lo; /* assuming f is decreasing */
while (lo < hi) { /* find last index such that f is true */
T mid = lo + (hi - lo + 1) / 2;
f(mid) ? lo = mid : hi = mid - 1;
} return lo;
}
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:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | scanf("%d%d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~
feast.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%d", a + i);
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
460 ms |
19652 KB |
Output is correct |
2 |
Correct |
484 ms |
20284 KB |
Output is correct |
3 |
Correct |
480 ms |
20416 KB |
Output is correct |
4 |
Correct |
459 ms |
20420 KB |
Output is correct |
5 |
Correct |
466 ms |
20384 KB |
Output is correct |
6 |
Correct |
448 ms |
19908 KB |
Output is correct |
7 |
Correct |
465 ms |
19924 KB |
Output is correct |
8 |
Correct |
462 ms |
20380 KB |
Output is correct |
9 |
Correct |
459 ms |
20044 KB |
Output is correct |
10 |
Correct |
474 ms |
20276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
451 ms |
19808 KB |
Output is correct |
2 |
Correct |
476 ms |
20196 KB |
Output is correct |
3 |
Correct |
460 ms |
19736 KB |
Output is correct |
4 |
Correct |
442 ms |
19908 KB |
Output is correct |
5 |
Correct |
462 ms |
19956 KB |
Output is correct |
6 |
Correct |
468 ms |
20076 KB |
Output is correct |
7 |
Correct |
465 ms |
20524 KB |
Output is correct |
8 |
Correct |
465 ms |
20392 KB |
Output is correct |
9 |
Correct |
468 ms |
19932 KB |
Output is correct |
10 |
Correct |
465 ms |
20420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
534 ms |
20136 KB |
Output is correct |
2 |
Correct |
533 ms |
19760 KB |
Output is correct |
3 |
Correct |
539 ms |
19948 KB |
Output is correct |
4 |
Correct |
514 ms |
19780 KB |
Output is correct |
5 |
Correct |
519 ms |
19952 KB |
Output is correct |
6 |
Correct |
525 ms |
20036 KB |
Output is correct |
7 |
Correct |
527 ms |
20152 KB |
Output is correct |
8 |
Correct |
525 ms |
19956 KB |
Output is correct |
9 |
Correct |
539 ms |
20264 KB |
Output is correct |
10 |
Correct |
523 ms |
20156 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 |
204 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 |
2 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 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 |
204 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 |
2 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
4 ms |
332 KB |
Output is correct |
22 |
Correct |
5 ms |
332 KB |
Output is correct |
23 |
Correct |
4 ms |
460 KB |
Output is correct |
24 |
Correct |
4 ms |
332 KB |
Output is correct |
25 |
Correct |
4 ms |
460 KB |
Output is correct |
26 |
Correct |
4 ms |
460 KB |
Output is correct |
27 |
Correct |
5 ms |
440 KB |
Output is correct |
28 |
Correct |
4 ms |
440 KB |
Output is correct |
29 |
Correct |
4 ms |
460 KB |
Output is correct |
30 |
Correct |
4 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
460 ms |
19652 KB |
Output is correct |
2 |
Correct |
484 ms |
20284 KB |
Output is correct |
3 |
Correct |
480 ms |
20416 KB |
Output is correct |
4 |
Correct |
459 ms |
20420 KB |
Output is correct |
5 |
Correct |
466 ms |
20384 KB |
Output is correct |
6 |
Correct |
448 ms |
19908 KB |
Output is correct |
7 |
Correct |
465 ms |
19924 KB |
Output is correct |
8 |
Correct |
462 ms |
20380 KB |
Output is correct |
9 |
Correct |
459 ms |
20044 KB |
Output is correct |
10 |
Correct |
474 ms |
20276 KB |
Output is correct |
11 |
Correct |
451 ms |
19808 KB |
Output is correct |
12 |
Correct |
476 ms |
20196 KB |
Output is correct |
13 |
Correct |
460 ms |
19736 KB |
Output is correct |
14 |
Correct |
442 ms |
19908 KB |
Output is correct |
15 |
Correct |
462 ms |
19956 KB |
Output is correct |
16 |
Correct |
468 ms |
20076 KB |
Output is correct |
17 |
Correct |
465 ms |
20524 KB |
Output is correct |
18 |
Correct |
465 ms |
20392 KB |
Output is correct |
19 |
Correct |
468 ms |
19932 KB |
Output is correct |
20 |
Correct |
465 ms |
20420 KB |
Output is correct |
21 |
Correct |
534 ms |
20136 KB |
Output is correct |
22 |
Correct |
533 ms |
19760 KB |
Output is correct |
23 |
Correct |
539 ms |
19948 KB |
Output is correct |
24 |
Correct |
514 ms |
19780 KB |
Output is correct |
25 |
Correct |
519 ms |
19952 KB |
Output is correct |
26 |
Correct |
525 ms |
20036 KB |
Output is correct |
27 |
Correct |
527 ms |
20152 KB |
Output is correct |
28 |
Correct |
525 ms |
19956 KB |
Output is correct |
29 |
Correct |
539 ms |
20264 KB |
Output is correct |
30 |
Correct |
523 ms |
20156 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 |
204 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 |
2 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
1 ms |
332 KB |
Output is correct |
50 |
Correct |
1 ms |
204 KB |
Output is correct |
51 |
Correct |
4 ms |
332 KB |
Output is correct |
52 |
Correct |
5 ms |
332 KB |
Output is correct |
53 |
Correct |
4 ms |
460 KB |
Output is correct |
54 |
Correct |
4 ms |
332 KB |
Output is correct |
55 |
Correct |
4 ms |
460 KB |
Output is correct |
56 |
Correct |
4 ms |
460 KB |
Output is correct |
57 |
Correct |
5 ms |
440 KB |
Output is correct |
58 |
Correct |
4 ms |
440 KB |
Output is correct |
59 |
Correct |
4 ms |
460 KB |
Output is correct |
60 |
Correct |
4 ms |
332 KB |
Output is correct |
61 |
Correct |
649 ms |
20028 KB |
Output is correct |
62 |
Correct |
636 ms |
20548 KB |
Output is correct |
63 |
Correct |
579 ms |
19980 KB |
Output is correct |
64 |
Correct |
675 ms |
20372 KB |
Output is correct |
65 |
Correct |
666 ms |
23112 KB |
Output is correct |
66 |
Correct |
663 ms |
23108 KB |
Output is correct |
67 |
Correct |
672 ms |
22692 KB |
Output is correct |
68 |
Correct |
537 ms |
23120 KB |
Output is correct |
69 |
Correct |
558 ms |
22672 KB |
Output is correct |
70 |
Correct |
524 ms |
22596 KB |
Output is correct |