# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
588046 |
2022-07-02T16:32:37 Z |
Temmie |
Feast (NOI19_feast) |
C++17 |
|
612 ms |
39744 KB |
#include <bits/stdc++.h>
typedef std::pair <long long, int> pa;
int n, k;
std::vector <int> a;
std::vector <std::vector <pa>> dp;
pa g(long long l) {
for (int i = 0; i < n; i++) for (int j = 0; j < 2; j++) dp[i][j] = { -1, -1 };
auto f = [&] (auto&& self, int i, bool is) -> pa {
if (i >= n) {
return { 0, 0 };
}
if (dp[i][is].second != -1) {
return dp[i][is];
}
dp[i][is] = self(self, i + 1, false);
pa cand = self(self, i + 1, true);
cand.second += !is;
cand.first += a[i];
cand.first -= l * !is;
dp[i][is] = std::max(dp[i][is], cand);
return dp[i][is];
};
return f(f, 0, false);
}
int main() {
std::ios::sync_with_stdio(0); std::cin.tie(0);
std::cin >> n >> k;
dp.resize(n, std::vector <pa> (2));
a.resize(n);
for (int& x : a) {
std::cin >> x;
}
long long l = 0, r = 1LL << 42, ans = 0;
while (l <= r) {
long long mid = (l + r) >> 1;
pa val = g(mid);
if (val.second > k) {
l = mid + 1;
} else {
r = mid - 1;
ans = val.first + mid * k;
}
}
std::cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
493 ms |
35844 KB |
Output is correct |
2 |
Correct |
485 ms |
36376 KB |
Output is correct |
3 |
Correct |
490 ms |
38476 KB |
Output is correct |
4 |
Correct |
509 ms |
36532 KB |
Output is correct |
5 |
Correct |
462 ms |
36784 KB |
Output is correct |
6 |
Correct |
470 ms |
35728 KB |
Output is correct |
7 |
Correct |
469 ms |
36716 KB |
Output is correct |
8 |
Correct |
462 ms |
36428 KB |
Output is correct |
9 |
Correct |
493 ms |
37492 KB |
Output is correct |
10 |
Correct |
469 ms |
37868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
462 ms |
36120 KB |
Output is correct |
2 |
Correct |
482 ms |
36884 KB |
Output is correct |
3 |
Correct |
452 ms |
36156 KB |
Output is correct |
4 |
Correct |
481 ms |
36472 KB |
Output is correct |
5 |
Correct |
482 ms |
36892 KB |
Output is correct |
6 |
Correct |
459 ms |
36384 KB |
Output is correct |
7 |
Correct |
461 ms |
37836 KB |
Output is correct |
8 |
Correct |
483 ms |
39244 KB |
Output is correct |
9 |
Correct |
534 ms |
38260 KB |
Output is correct |
10 |
Correct |
460 ms |
37576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
506 ms |
36544 KB |
Output is correct |
2 |
Correct |
492 ms |
36296 KB |
Output is correct |
3 |
Correct |
490 ms |
36524 KB |
Output is correct |
4 |
Correct |
479 ms |
36172 KB |
Output is correct |
5 |
Correct |
491 ms |
36436 KB |
Output is correct |
6 |
Correct |
541 ms |
38220 KB |
Output is correct |
7 |
Correct |
507 ms |
38476 KB |
Output is correct |
8 |
Correct |
498 ms |
36440 KB |
Output is correct |
9 |
Correct |
511 ms |
36660 KB |
Output is correct |
10 |
Correct |
509 ms |
36724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
320 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 |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
320 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 |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
212 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 |
352 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
320 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 |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
212 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 |
352 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 |
4 ms |
468 KB |
Output is correct |
22 |
Correct |
4 ms |
596 KB |
Output is correct |
23 |
Correct |
3 ms |
468 KB |
Output is correct |
24 |
Correct |
4 ms |
468 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
596 KB |
Output is correct |
28 |
Correct |
3 ms |
588 KB |
Output is correct |
29 |
Correct |
3 ms |
492 KB |
Output is correct |
30 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
493 ms |
35844 KB |
Output is correct |
2 |
Correct |
485 ms |
36376 KB |
Output is correct |
3 |
Correct |
490 ms |
38476 KB |
Output is correct |
4 |
Correct |
509 ms |
36532 KB |
Output is correct |
5 |
Correct |
462 ms |
36784 KB |
Output is correct |
6 |
Correct |
470 ms |
35728 KB |
Output is correct |
7 |
Correct |
469 ms |
36716 KB |
Output is correct |
8 |
Correct |
462 ms |
36428 KB |
Output is correct |
9 |
Correct |
493 ms |
37492 KB |
Output is correct |
10 |
Correct |
469 ms |
37868 KB |
Output is correct |
11 |
Correct |
462 ms |
36120 KB |
Output is correct |
12 |
Correct |
482 ms |
36884 KB |
Output is correct |
13 |
Correct |
452 ms |
36156 KB |
Output is correct |
14 |
Correct |
481 ms |
36472 KB |
Output is correct |
15 |
Correct |
482 ms |
36892 KB |
Output is correct |
16 |
Correct |
459 ms |
36384 KB |
Output is correct |
17 |
Correct |
461 ms |
37836 KB |
Output is correct |
18 |
Correct |
483 ms |
39244 KB |
Output is correct |
19 |
Correct |
534 ms |
38260 KB |
Output is correct |
20 |
Correct |
460 ms |
37576 KB |
Output is correct |
21 |
Correct |
506 ms |
36544 KB |
Output is correct |
22 |
Correct |
492 ms |
36296 KB |
Output is correct |
23 |
Correct |
490 ms |
36524 KB |
Output is correct |
24 |
Correct |
479 ms |
36172 KB |
Output is correct |
25 |
Correct |
491 ms |
36436 KB |
Output is correct |
26 |
Correct |
541 ms |
38220 KB |
Output is correct |
27 |
Correct |
507 ms |
38476 KB |
Output is correct |
28 |
Correct |
498 ms |
36440 KB |
Output is correct |
29 |
Correct |
511 ms |
36660 KB |
Output is correct |
30 |
Correct |
509 ms |
36724 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
320 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
316 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
316 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
316 KB |
Output is correct |
40 |
Correct |
1 ms |
212 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 |
352 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 |
4 ms |
468 KB |
Output is correct |
52 |
Correct |
4 ms |
596 KB |
Output is correct |
53 |
Correct |
3 ms |
468 KB |
Output is correct |
54 |
Correct |
4 ms |
468 KB |
Output is correct |
55 |
Correct |
3 ms |
468 KB |
Output is correct |
56 |
Correct |
3 ms |
468 KB |
Output is correct |
57 |
Correct |
3 ms |
596 KB |
Output is correct |
58 |
Correct |
3 ms |
588 KB |
Output is correct |
59 |
Correct |
3 ms |
492 KB |
Output is correct |
60 |
Correct |
3 ms |
468 KB |
Output is correct |
61 |
Correct |
554 ms |
38672 KB |
Output is correct |
62 |
Correct |
562 ms |
39744 KB |
Output is correct |
63 |
Correct |
513 ms |
38660 KB |
Output is correct |
64 |
Correct |
612 ms |
39440 KB |
Output is correct |
65 |
Correct |
592 ms |
39308 KB |
Output is correct |
66 |
Correct |
563 ms |
39156 KB |
Output is correct |
67 |
Correct |
571 ms |
36376 KB |
Output is correct |
68 |
Correct |
513 ms |
37908 KB |
Output is correct |
69 |
Correct |
494 ms |
38652 KB |
Output is correct |
70 |
Correct |
484 ms |
37924 KB |
Output is correct |