# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1097319 |
2024-10-06T19:57:33 Z |
vjudge1 |
Feast (NOI19_feast) |
C++17 |
|
484 ms |
47440 KB |
#include<bits/stdc++.h>
using namespace std;
const int N = 3e5 + 2;
int n, vis[N][2];
long long pan, a[N];
pair<long long, int> mem[N][2];
pair<long long, int> operator + (pair<long long, int> x, pair<long long, int> y) {
return make_pair(x.first + y.first, x.second + y.second);
}
// 0-> (i - 1) not taken vice verca
pair<long long, int> dp(int i, int f) {
if (i == n) return {0, 0};
if (vis[i][f]) return mem[i][f];
vis[i][f] = 1;
auto &ret = mem[i][f];
ret = dp(i + 1, 0);
ret = max(ret, dp(i + 1, 1) + make_pair(a[i] - pan * !f, -1 * !f));
return ret;
}
pair<long long, int> get(long long x) {
pan = x;
memset(vis, 0, sizeof(vis));
return dp(0, 0);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int k;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i];
// auto z = get(1);
// cout << z.first << endl;
// cout << z.second << endl;
long long l = 0, r = 1LL << 42, res = 0;
while (l <= r) {
long long m = (l + r) / 2;
auto [x, y] = get(m);
if (-y <= k) {
res = x + k * m;
r = m - 1;
} else l = m + 1;
}
cout << res << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
399 ms |
45908 KB |
Output is correct |
2 |
Correct |
405 ms |
46948 KB |
Output is correct |
3 |
Correct |
417 ms |
47324 KB |
Output is correct |
4 |
Correct |
408 ms |
46932 KB |
Output is correct |
5 |
Correct |
418 ms |
46672 KB |
Output is correct |
6 |
Correct |
420 ms |
46040 KB |
Output is correct |
7 |
Correct |
413 ms |
46024 KB |
Output is correct |
8 |
Correct |
412 ms |
46720 KB |
Output is correct |
9 |
Correct |
411 ms |
46132 KB |
Output is correct |
10 |
Correct |
417 ms |
46416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
480 ms |
46316 KB |
Output is correct |
2 |
Correct |
396 ms |
47440 KB |
Output is correct |
3 |
Correct |
389 ms |
46248 KB |
Output is correct |
4 |
Correct |
414 ms |
46724 KB |
Output is correct |
5 |
Correct |
403 ms |
46076 KB |
Output is correct |
6 |
Correct |
375 ms |
46160 KB |
Output is correct |
7 |
Correct |
434 ms |
47188 KB |
Output is correct |
8 |
Correct |
433 ms |
46976 KB |
Output is correct |
9 |
Correct |
402 ms |
45932 KB |
Output is correct |
10 |
Correct |
419 ms |
46932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
455 ms |
46672 KB |
Output is correct |
2 |
Correct |
426 ms |
46160 KB |
Output is correct |
3 |
Correct |
455 ms |
46760 KB |
Output is correct |
4 |
Correct |
451 ms |
46160 KB |
Output is correct |
5 |
Correct |
451 ms |
46672 KB |
Output is correct |
6 |
Correct |
464 ms |
46968 KB |
Output is correct |
7 |
Correct |
457 ms |
47180 KB |
Output is correct |
8 |
Correct |
461 ms |
46764 KB |
Output is correct |
9 |
Correct |
452 ms |
47176 KB |
Output is correct |
10 |
Correct |
433 ms |
47068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2648 KB |
Output is correct |
2 |
Correct |
3 ms |
2652 KB |
Output is correct |
3 |
Correct |
4 ms |
2652 KB |
Output is correct |
4 |
Correct |
5 ms |
2652 KB |
Output is correct |
5 |
Correct |
4 ms |
2652 KB |
Output is correct |
6 |
Correct |
3 ms |
2824 KB |
Output is correct |
7 |
Correct |
3 ms |
2652 KB |
Output is correct |
8 |
Correct |
4 ms |
2652 KB |
Output is correct |
9 |
Correct |
4 ms |
2652 KB |
Output is correct |
10 |
Correct |
3 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2648 KB |
Output is correct |
2 |
Correct |
3 ms |
2652 KB |
Output is correct |
3 |
Correct |
4 ms |
2652 KB |
Output is correct |
4 |
Correct |
5 ms |
2652 KB |
Output is correct |
5 |
Correct |
4 ms |
2652 KB |
Output is correct |
6 |
Correct |
3 ms |
2824 KB |
Output is correct |
7 |
Correct |
3 ms |
2652 KB |
Output is correct |
8 |
Correct |
4 ms |
2652 KB |
Output is correct |
9 |
Correct |
4 ms |
2652 KB |
Output is correct |
10 |
Correct |
3 ms |
2652 KB |
Output is correct |
11 |
Correct |
4 ms |
2652 KB |
Output is correct |
12 |
Correct |
4 ms |
2652 KB |
Output is correct |
13 |
Correct |
4 ms |
2652 KB |
Output is correct |
14 |
Correct |
4 ms |
2652 KB |
Output is correct |
15 |
Correct |
5 ms |
2652 KB |
Output is correct |
16 |
Correct |
4 ms |
2828 KB |
Output is correct |
17 |
Correct |
4 ms |
2856 KB |
Output is correct |
18 |
Correct |
4 ms |
2652 KB |
Output is correct |
19 |
Correct |
4 ms |
2652 KB |
Output is correct |
20 |
Correct |
3 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2648 KB |
Output is correct |
2 |
Correct |
3 ms |
2652 KB |
Output is correct |
3 |
Correct |
4 ms |
2652 KB |
Output is correct |
4 |
Correct |
5 ms |
2652 KB |
Output is correct |
5 |
Correct |
4 ms |
2652 KB |
Output is correct |
6 |
Correct |
3 ms |
2824 KB |
Output is correct |
7 |
Correct |
3 ms |
2652 KB |
Output is correct |
8 |
Correct |
4 ms |
2652 KB |
Output is correct |
9 |
Correct |
4 ms |
2652 KB |
Output is correct |
10 |
Correct |
3 ms |
2652 KB |
Output is correct |
11 |
Correct |
4 ms |
2652 KB |
Output is correct |
12 |
Correct |
4 ms |
2652 KB |
Output is correct |
13 |
Correct |
4 ms |
2652 KB |
Output is correct |
14 |
Correct |
4 ms |
2652 KB |
Output is correct |
15 |
Correct |
5 ms |
2652 KB |
Output is correct |
16 |
Correct |
4 ms |
2828 KB |
Output is correct |
17 |
Correct |
4 ms |
2856 KB |
Output is correct |
18 |
Correct |
4 ms |
2652 KB |
Output is correct |
19 |
Correct |
4 ms |
2652 KB |
Output is correct |
20 |
Correct |
3 ms |
2652 KB |
Output is correct |
21 |
Correct |
5 ms |
2908 KB |
Output is correct |
22 |
Correct |
6 ms |
3100 KB |
Output is correct |
23 |
Correct |
5 ms |
2904 KB |
Output is correct |
24 |
Correct |
7 ms |
3100 KB |
Output is correct |
25 |
Correct |
7 ms |
2904 KB |
Output is correct |
26 |
Correct |
6 ms |
2908 KB |
Output is correct |
27 |
Correct |
5 ms |
3108 KB |
Output is correct |
28 |
Correct |
5 ms |
2908 KB |
Output is correct |
29 |
Correct |
5 ms |
2908 KB |
Output is correct |
30 |
Correct |
5 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
399 ms |
45908 KB |
Output is correct |
2 |
Correct |
405 ms |
46948 KB |
Output is correct |
3 |
Correct |
417 ms |
47324 KB |
Output is correct |
4 |
Correct |
408 ms |
46932 KB |
Output is correct |
5 |
Correct |
418 ms |
46672 KB |
Output is correct |
6 |
Correct |
420 ms |
46040 KB |
Output is correct |
7 |
Correct |
413 ms |
46024 KB |
Output is correct |
8 |
Correct |
412 ms |
46720 KB |
Output is correct |
9 |
Correct |
411 ms |
46132 KB |
Output is correct |
10 |
Correct |
417 ms |
46416 KB |
Output is correct |
11 |
Correct |
480 ms |
46316 KB |
Output is correct |
12 |
Correct |
396 ms |
47440 KB |
Output is correct |
13 |
Correct |
389 ms |
46248 KB |
Output is correct |
14 |
Correct |
414 ms |
46724 KB |
Output is correct |
15 |
Correct |
403 ms |
46076 KB |
Output is correct |
16 |
Correct |
375 ms |
46160 KB |
Output is correct |
17 |
Correct |
434 ms |
47188 KB |
Output is correct |
18 |
Correct |
433 ms |
46976 KB |
Output is correct |
19 |
Correct |
402 ms |
45932 KB |
Output is correct |
20 |
Correct |
419 ms |
46932 KB |
Output is correct |
21 |
Correct |
455 ms |
46672 KB |
Output is correct |
22 |
Correct |
426 ms |
46160 KB |
Output is correct |
23 |
Correct |
455 ms |
46760 KB |
Output is correct |
24 |
Correct |
451 ms |
46160 KB |
Output is correct |
25 |
Correct |
451 ms |
46672 KB |
Output is correct |
26 |
Correct |
464 ms |
46968 KB |
Output is correct |
27 |
Correct |
457 ms |
47180 KB |
Output is correct |
28 |
Correct |
461 ms |
46764 KB |
Output is correct |
29 |
Correct |
452 ms |
47176 KB |
Output is correct |
30 |
Correct |
433 ms |
47068 KB |
Output is correct |
31 |
Correct |
3 ms |
2648 KB |
Output is correct |
32 |
Correct |
3 ms |
2652 KB |
Output is correct |
33 |
Correct |
4 ms |
2652 KB |
Output is correct |
34 |
Correct |
5 ms |
2652 KB |
Output is correct |
35 |
Correct |
4 ms |
2652 KB |
Output is correct |
36 |
Correct |
3 ms |
2824 KB |
Output is correct |
37 |
Correct |
3 ms |
2652 KB |
Output is correct |
38 |
Correct |
4 ms |
2652 KB |
Output is correct |
39 |
Correct |
4 ms |
2652 KB |
Output is correct |
40 |
Correct |
3 ms |
2652 KB |
Output is correct |
41 |
Correct |
4 ms |
2652 KB |
Output is correct |
42 |
Correct |
4 ms |
2652 KB |
Output is correct |
43 |
Correct |
4 ms |
2652 KB |
Output is correct |
44 |
Correct |
4 ms |
2652 KB |
Output is correct |
45 |
Correct |
5 ms |
2652 KB |
Output is correct |
46 |
Correct |
4 ms |
2828 KB |
Output is correct |
47 |
Correct |
4 ms |
2856 KB |
Output is correct |
48 |
Correct |
4 ms |
2652 KB |
Output is correct |
49 |
Correct |
4 ms |
2652 KB |
Output is correct |
50 |
Correct |
3 ms |
2652 KB |
Output is correct |
51 |
Correct |
5 ms |
2908 KB |
Output is correct |
52 |
Correct |
6 ms |
3100 KB |
Output is correct |
53 |
Correct |
5 ms |
2904 KB |
Output is correct |
54 |
Correct |
7 ms |
3100 KB |
Output is correct |
55 |
Correct |
7 ms |
2904 KB |
Output is correct |
56 |
Correct |
6 ms |
2908 KB |
Output is correct |
57 |
Correct |
5 ms |
3108 KB |
Output is correct |
58 |
Correct |
5 ms |
2908 KB |
Output is correct |
59 |
Correct |
5 ms |
2908 KB |
Output is correct |
60 |
Correct |
5 ms |
2908 KB |
Output is correct |
61 |
Correct |
483 ms |
46264 KB |
Output is correct |
62 |
Correct |
431 ms |
47128 KB |
Output is correct |
63 |
Correct |
417 ms |
45908 KB |
Output is correct |
64 |
Correct |
448 ms |
46820 KB |
Output is correct |
65 |
Correct |
455 ms |
46996 KB |
Output is correct |
66 |
Correct |
484 ms |
46880 KB |
Output is correct |
67 |
Correct |
478 ms |
46160 KB |
Output is correct |
68 |
Correct |
445 ms |
46932 KB |
Output is correct |
69 |
Correct |
439 ms |
46160 KB |
Output is correct |
70 |
Correct |
457 ms |
45980 KB |
Output is correct |