# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1023161 |
2024-07-14T11:24:56 Z |
avighna |
Feast (NOI19_feast) |
C++17 |
|
145 ms |
15196 KB |
#include <bits/stdc++.h>
typedef long long ll;
const ll N = 3e5 + 1;
std::pair<ll, ll> dp[N][2];
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n, k;
std::cin >> n >> k;
std::vector<ll> a(n);
for (auto &i : a) {
std::cin >> i;
}
auto solve_dp = [&](ll p) {
dp[0][0] = {0, 0};
dp[0][1] = {a[0] - p, 1};
for (ll i = 1; i < n; ++ i) {
dp[i][1] = std::max(std::make_pair<ll, ll>(a[i] + dp[i - 1][1].first, ll(dp[i - 1][1].second)), std::make_pair<ll, ll>(a[i] + dp[i - 1][0].first - p, dp[i - 1][0].second + 1));
dp[i][0] = std::max(dp[i - 1][0], dp[i - 1][1]);
}
dp[n][0] = std::max(dp[n - 1][0], dp[n - 1][1]);
return dp[n][0];
};
ll lo = 0, hi = 1e18;
for (ll i = 0; i < 64; ++ i) {
ll p = (lo + hi) / 2;
if (solve_dp(p).second <= k) {
hi = p;
} else {
lo = p;
}
}
auto dp = solve_dp(hi);
std::cout << dp.first + dp.second * hi << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
14420 KB |
Output is correct |
2 |
Correct |
69 ms |
14672 KB |
Output is correct |
3 |
Correct |
71 ms |
14932 KB |
Output is correct |
4 |
Correct |
69 ms |
14932 KB |
Output is correct |
5 |
Correct |
71 ms |
14668 KB |
Output is correct |
6 |
Correct |
76 ms |
14628 KB |
Output is correct |
7 |
Correct |
66 ms |
14416 KB |
Output is correct |
8 |
Correct |
69 ms |
14936 KB |
Output is correct |
9 |
Correct |
67 ms |
14684 KB |
Output is correct |
10 |
Correct |
70 ms |
14672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
12880 KB |
Output is correct |
2 |
Correct |
59 ms |
13164 KB |
Output is correct |
3 |
Correct |
73 ms |
12932 KB |
Output is correct |
4 |
Correct |
58 ms |
12888 KB |
Output is correct |
5 |
Correct |
67 ms |
14508 KB |
Output is correct |
6 |
Correct |
57 ms |
12892 KB |
Output is correct |
7 |
Correct |
61 ms |
13144 KB |
Output is correct |
8 |
Correct |
65 ms |
14932 KB |
Output is correct |
9 |
Correct |
60 ms |
14428 KB |
Output is correct |
10 |
Correct |
54 ms |
13144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
14924 KB |
Output is correct |
2 |
Correct |
79 ms |
14672 KB |
Output is correct |
3 |
Correct |
89 ms |
14876 KB |
Output is correct |
4 |
Correct |
80 ms |
14644 KB |
Output is correct |
5 |
Correct |
73 ms |
14936 KB |
Output is correct |
6 |
Correct |
75 ms |
14940 KB |
Output is correct |
7 |
Correct |
77 ms |
15196 KB |
Output is correct |
8 |
Correct |
76 ms |
14940 KB |
Output is correct |
9 |
Correct |
75 ms |
15084 KB |
Output is correct |
10 |
Correct |
90 ms |
14932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
14420 KB |
Output is correct |
2 |
Correct |
69 ms |
14672 KB |
Output is correct |
3 |
Correct |
71 ms |
14932 KB |
Output is correct |
4 |
Correct |
69 ms |
14932 KB |
Output is correct |
5 |
Correct |
71 ms |
14668 KB |
Output is correct |
6 |
Correct |
76 ms |
14628 KB |
Output is correct |
7 |
Correct |
66 ms |
14416 KB |
Output is correct |
8 |
Correct |
69 ms |
14936 KB |
Output is correct |
9 |
Correct |
67 ms |
14684 KB |
Output is correct |
10 |
Correct |
70 ms |
14672 KB |
Output is correct |
11 |
Correct |
57 ms |
12880 KB |
Output is correct |
12 |
Correct |
59 ms |
13164 KB |
Output is correct |
13 |
Correct |
73 ms |
12932 KB |
Output is correct |
14 |
Correct |
58 ms |
12888 KB |
Output is correct |
15 |
Correct |
67 ms |
14508 KB |
Output is correct |
16 |
Correct |
57 ms |
12892 KB |
Output is correct |
17 |
Correct |
61 ms |
13144 KB |
Output is correct |
18 |
Correct |
65 ms |
14932 KB |
Output is correct |
19 |
Correct |
60 ms |
14428 KB |
Output is correct |
20 |
Correct |
54 ms |
13144 KB |
Output is correct |
21 |
Correct |
79 ms |
14924 KB |
Output is correct |
22 |
Correct |
79 ms |
14672 KB |
Output is correct |
23 |
Correct |
89 ms |
14876 KB |
Output is correct |
24 |
Correct |
80 ms |
14644 KB |
Output is correct |
25 |
Correct |
73 ms |
14936 KB |
Output is correct |
26 |
Correct |
75 ms |
14940 KB |
Output is correct |
27 |
Correct |
77 ms |
15196 KB |
Output is correct |
28 |
Correct |
76 ms |
14940 KB |
Output is correct |
29 |
Correct |
75 ms |
15084 KB |
Output is correct |
30 |
Correct |
90 ms |
14932 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
600 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
464 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
1 ms |
348 KB |
Output is correct |
52 |
Correct |
1 ms |
348 KB |
Output is correct |
53 |
Correct |
1 ms |
348 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
1 ms |
348 KB |
Output is correct |
56 |
Correct |
1 ms |
348 KB |
Output is correct |
57 |
Correct |
1 ms |
348 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
145 ms |
14780 KB |
Output is correct |
62 |
Correct |
123 ms |
15188 KB |
Output is correct |
63 |
Correct |
103 ms |
14680 KB |
Output is correct |
64 |
Correct |
137 ms |
14932 KB |
Output is correct |
65 |
Correct |
135 ms |
14940 KB |
Output is correct |
66 |
Correct |
137 ms |
14924 KB |
Output is correct |
67 |
Correct |
132 ms |
14684 KB |
Output is correct |
68 |
Correct |
88 ms |
14928 KB |
Output is correct |
69 |
Correct |
86 ms |
14672 KB |
Output is correct |
70 |
Correct |
84 ms |
14684 KB |
Output is correct |