# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
988367 |
2024-05-24T14:43:43 Z |
vjudge1 |
Feast (NOI19_feast) |
C++17 |
|
260 ms |
27164 KB |
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
int n, k;
vector<long long> a;
vector<vector<pair<long long, long long> > > DP;
pair<long long, long long> dp(long long lambda)
{
DP[0][0] = { 0, 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][0].first + a[i] - lambda, DP[i - 1][0].second + 1),
make_pair(DP[i - 1][1].first + a[i], DP[i - 1][1].second)
);
}
return max(DP[n][0], DP[n][1]);
}
int main()
{
cin >> n >> k;
DP.resize(n + 1, vector<pair<long long, long long>>(2, { LLONG_MIN / 4, 0 }));
a.resize(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
long long l = 0, r = 3e14, lambda;
while ( r - l > 1)
{
lambda = (l + r) / 2;
auto m = dp(lambda);
if (m.second > k) l = lambda;
else r = lambda;
}
auto megoldas = dp(r);
cout << megoldas.first + megoldas.second * r;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
23172 KB |
Output is correct |
2 |
Correct |
191 ms |
23384 KB |
Output is correct |
3 |
Correct |
200 ms |
23640 KB |
Output is correct |
4 |
Correct |
194 ms |
23712 KB |
Output is correct |
5 |
Correct |
176 ms |
23580 KB |
Output is correct |
6 |
Correct |
186 ms |
23132 KB |
Output is correct |
7 |
Correct |
173 ms |
23284 KB |
Output is correct |
8 |
Correct |
192 ms |
23640 KB |
Output is correct |
9 |
Correct |
172 ms |
23132 KB |
Output is correct |
10 |
Correct |
188 ms |
23472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
145 ms |
23328 KB |
Output is correct |
2 |
Correct |
160 ms |
23644 KB |
Output is correct |
3 |
Correct |
150 ms |
23304 KB |
Output is correct |
4 |
Correct |
152 ms |
23384 KB |
Output is correct |
5 |
Correct |
183 ms |
23128 KB |
Output is correct |
6 |
Correct |
168 ms |
23128 KB |
Output is correct |
7 |
Correct |
157 ms |
23900 KB |
Output is correct |
8 |
Correct |
197 ms |
23644 KB |
Output is correct |
9 |
Correct |
166 ms |
23136 KB |
Output is correct |
10 |
Correct |
157 ms |
23644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
196 ms |
23640 KB |
Output is correct |
2 |
Correct |
204 ms |
26196 KB |
Output is correct |
3 |
Correct |
201 ms |
26492 KB |
Output is correct |
4 |
Correct |
202 ms |
26192 KB |
Output is correct |
5 |
Correct |
205 ms |
26708 KB |
Output is correct |
6 |
Correct |
208 ms |
26736 KB |
Output is correct |
7 |
Correct |
210 ms |
26732 KB |
Output is correct |
8 |
Correct |
210 ms |
26768 KB |
Output is correct |
9 |
Correct |
205 ms |
26708 KB |
Output is correct |
10 |
Correct |
231 ms |
26724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
436 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
436 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
440 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
436 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
440 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
2 ms |
600 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
2 ms |
856 KB |
Output is correct |
27 |
Correct |
2 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
23172 KB |
Output is correct |
2 |
Correct |
191 ms |
23384 KB |
Output is correct |
3 |
Correct |
200 ms |
23640 KB |
Output is correct |
4 |
Correct |
194 ms |
23712 KB |
Output is correct |
5 |
Correct |
176 ms |
23580 KB |
Output is correct |
6 |
Correct |
186 ms |
23132 KB |
Output is correct |
7 |
Correct |
173 ms |
23284 KB |
Output is correct |
8 |
Correct |
192 ms |
23640 KB |
Output is correct |
9 |
Correct |
172 ms |
23132 KB |
Output is correct |
10 |
Correct |
188 ms |
23472 KB |
Output is correct |
11 |
Correct |
145 ms |
23328 KB |
Output is correct |
12 |
Correct |
160 ms |
23644 KB |
Output is correct |
13 |
Correct |
150 ms |
23304 KB |
Output is correct |
14 |
Correct |
152 ms |
23384 KB |
Output is correct |
15 |
Correct |
183 ms |
23128 KB |
Output is correct |
16 |
Correct |
168 ms |
23128 KB |
Output is correct |
17 |
Correct |
157 ms |
23900 KB |
Output is correct |
18 |
Correct |
197 ms |
23644 KB |
Output is correct |
19 |
Correct |
166 ms |
23136 KB |
Output is correct |
20 |
Correct |
157 ms |
23644 KB |
Output is correct |
21 |
Correct |
196 ms |
23640 KB |
Output is correct |
22 |
Correct |
204 ms |
26196 KB |
Output is correct |
23 |
Correct |
201 ms |
26492 KB |
Output is correct |
24 |
Correct |
202 ms |
26192 KB |
Output is correct |
25 |
Correct |
205 ms |
26708 KB |
Output is correct |
26 |
Correct |
208 ms |
26736 KB |
Output is correct |
27 |
Correct |
210 ms |
26732 KB |
Output is correct |
28 |
Correct |
210 ms |
26768 KB |
Output is correct |
29 |
Correct |
205 ms |
26708 KB |
Output is correct |
30 |
Correct |
231 ms |
26724 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
436 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
45 |
Correct |
1 ms |
440 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
344 KB |
Output is correct |
51 |
Correct |
2 ms |
600 KB |
Output is correct |
52 |
Correct |
2 ms |
600 KB |
Output is correct |
53 |
Correct |
2 ms |
604 KB |
Output is correct |
54 |
Correct |
2 ms |
604 KB |
Output is correct |
55 |
Correct |
2 ms |
600 KB |
Output is correct |
56 |
Correct |
2 ms |
856 KB |
Output is correct |
57 |
Correct |
2 ms |
600 KB |
Output is correct |
58 |
Correct |
1 ms |
604 KB |
Output is correct |
59 |
Correct |
2 ms |
604 KB |
Output is correct |
60 |
Correct |
1 ms |
448 KB |
Output is correct |
61 |
Correct |
218 ms |
26232 KB |
Output is correct |
62 |
Correct |
224 ms |
27164 KB |
Output is correct |
63 |
Correct |
195 ms |
26196 KB |
Output is correct |
64 |
Correct |
227 ms |
26644 KB |
Output is correct |
65 |
Correct |
260 ms |
26712 KB |
Output is correct |
66 |
Correct |
219 ms |
26440 KB |
Output is correct |
67 |
Correct |
221 ms |
26484 KB |
Output is correct |
68 |
Correct |
209 ms |
26704 KB |
Output is correct |
69 |
Correct |
202 ms |
26192 KB |
Output is correct |
70 |
Correct |
206 ms |
26200 KB |
Output is correct |