# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1109998 |
2024-11-08T11:59:21 Z |
NoMercy |
Feast (NOI19_feast) |
C++17 |
|
156 ms |
26852 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int32_t main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N, K;
cin >> N >> K;
vector<ll> arr(N + 1, 0);
for (int i = 1;i <= N;i ++) cin >> arr[i];
vector<vector<pair<ll, ll>>> dp(N + 1, {{0, 0}, {0, 0}});
auto calculate = [&](ll mid) -> void {
dp[1][0] = {0, 0};
dp[1][1] = {arr[1] - mid, 1};
for (int i = 2;i <= N;i ++) {
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
dp[i][1] = max(make_pair(dp[i - 1][0].first + arr[i] - mid, dp[i - 1][0].second + 1), make_pair(dp[i - 1][1].first + arr[i], dp[i - 1][1].second));
}
};
ll lo = 0, hi = 1e16 + 6789;
while (lo + 1 < hi) {
ll mid = (lo + hi) / 2LL;
calculate (mid);
if (max(dp[N][0], dp[N][1]).second < K) {
hi = mid;
} else {
lo = mid;
}
}
calculate (lo);
cout << max(dp[N][0], dp[N][1]).first + lo * K << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
25796 KB |
Output is correct |
2 |
Correct |
90 ms |
25408 KB |
Output is correct |
3 |
Correct |
92 ms |
26184 KB |
Output is correct |
4 |
Correct |
97 ms |
25028 KB |
Output is correct |
5 |
Correct |
89 ms |
26348 KB |
Output is correct |
6 |
Correct |
88 ms |
25928 KB |
Output is correct |
7 |
Correct |
90 ms |
26016 KB |
Output is correct |
8 |
Correct |
85 ms |
26324 KB |
Output is correct |
9 |
Correct |
87 ms |
24648 KB |
Output is correct |
10 |
Correct |
91 ms |
25300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
24484 KB |
Output is correct |
2 |
Correct |
81 ms |
24912 KB |
Output is correct |
3 |
Correct |
80 ms |
24392 KB |
Output is correct |
4 |
Correct |
88 ms |
24656 KB |
Output is correct |
5 |
Correct |
110 ms |
26008 KB |
Output is correct |
6 |
Correct |
87 ms |
24256 KB |
Output is correct |
7 |
Correct |
97 ms |
24964 KB |
Output is correct |
8 |
Correct |
88 ms |
26456 KB |
Output is correct |
9 |
Correct |
95 ms |
25928 KB |
Output is correct |
10 |
Correct |
83 ms |
24872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
26448 KB |
Output is correct |
2 |
Correct |
113 ms |
26184 KB |
Output is correct |
3 |
Correct |
127 ms |
26552 KB |
Output is correct |
4 |
Correct |
115 ms |
26184 KB |
Output is correct |
5 |
Correct |
122 ms |
26440 KB |
Output is correct |
6 |
Correct |
124 ms |
26624 KB |
Output is correct |
7 |
Correct |
115 ms |
26720 KB |
Output is correct |
8 |
Correct |
117 ms |
26440 KB |
Output is correct |
9 |
Correct |
126 ms |
26756 KB |
Output is correct |
10 |
Correct |
118 ms |
26696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
508 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
508 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
592 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
508 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
592 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
592 KB |
Output is correct |
22 |
Correct |
1 ms |
592 KB |
Output is correct |
23 |
Correct |
1 ms |
592 KB |
Output is correct |
24 |
Correct |
1 ms |
592 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
592 KB |
Output is correct |
27 |
Correct |
1 ms |
592 KB |
Output is correct |
28 |
Correct |
2 ms |
592 KB |
Output is correct |
29 |
Correct |
2 ms |
592 KB |
Output is correct |
30 |
Correct |
1 ms |
472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
25796 KB |
Output is correct |
2 |
Correct |
90 ms |
25408 KB |
Output is correct |
3 |
Correct |
92 ms |
26184 KB |
Output is correct |
4 |
Correct |
97 ms |
25028 KB |
Output is correct |
5 |
Correct |
89 ms |
26348 KB |
Output is correct |
6 |
Correct |
88 ms |
25928 KB |
Output is correct |
7 |
Correct |
90 ms |
26016 KB |
Output is correct |
8 |
Correct |
85 ms |
26324 KB |
Output is correct |
9 |
Correct |
87 ms |
24648 KB |
Output is correct |
10 |
Correct |
91 ms |
25300 KB |
Output is correct |
11 |
Correct |
83 ms |
24484 KB |
Output is correct |
12 |
Correct |
81 ms |
24912 KB |
Output is correct |
13 |
Correct |
80 ms |
24392 KB |
Output is correct |
14 |
Correct |
88 ms |
24656 KB |
Output is correct |
15 |
Correct |
110 ms |
26008 KB |
Output is correct |
16 |
Correct |
87 ms |
24256 KB |
Output is correct |
17 |
Correct |
97 ms |
24964 KB |
Output is correct |
18 |
Correct |
88 ms |
26456 KB |
Output is correct |
19 |
Correct |
95 ms |
25928 KB |
Output is correct |
20 |
Correct |
83 ms |
24872 KB |
Output is correct |
21 |
Correct |
112 ms |
26448 KB |
Output is correct |
22 |
Correct |
113 ms |
26184 KB |
Output is correct |
23 |
Correct |
127 ms |
26552 KB |
Output is correct |
24 |
Correct |
115 ms |
26184 KB |
Output is correct |
25 |
Correct |
122 ms |
26440 KB |
Output is correct |
26 |
Correct |
124 ms |
26624 KB |
Output is correct |
27 |
Correct |
115 ms |
26720 KB |
Output is correct |
28 |
Correct |
117 ms |
26440 KB |
Output is correct |
29 |
Correct |
126 ms |
26756 KB |
Output is correct |
30 |
Correct |
118 ms |
26696 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
504 KB |
Output is correct |
34 |
Correct |
1 ms |
508 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
464 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
592 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
336 KB |
Output is correct |
49 |
Correct |
1 ms |
336 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
2 ms |
592 KB |
Output is correct |
52 |
Correct |
1 ms |
592 KB |
Output is correct |
53 |
Correct |
1 ms |
592 KB |
Output is correct |
54 |
Correct |
1 ms |
592 KB |
Output is correct |
55 |
Correct |
2 ms |
604 KB |
Output is correct |
56 |
Correct |
2 ms |
592 KB |
Output is correct |
57 |
Correct |
1 ms |
592 KB |
Output is correct |
58 |
Correct |
2 ms |
592 KB |
Output is correct |
59 |
Correct |
2 ms |
592 KB |
Output is correct |
60 |
Correct |
1 ms |
472 KB |
Output is correct |
61 |
Correct |
135 ms |
26184 KB |
Output is correct |
62 |
Correct |
136 ms |
26852 KB |
Output is correct |
63 |
Correct |
137 ms |
26192 KB |
Output is correct |
64 |
Correct |
153 ms |
26720 KB |
Output is correct |
65 |
Correct |
156 ms |
26696 KB |
Output is correct |
66 |
Correct |
148 ms |
26440 KB |
Output is correct |
67 |
Correct |
148 ms |
26184 KB |
Output is correct |
68 |
Correct |
125 ms |
26572 KB |
Output is correct |
69 |
Correct |
109 ms |
26192 KB |
Output is correct |
70 |
Correct |
117 ms |
26144 KB |
Output is correct |