# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1097307 |
2024-10-06T19:34:35 Z |
vjudge1 |
Feast (NOI19_feast) |
C++17 |
|
473 ms |
50436 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);
}
// 1-> (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, 1);
ret = max(ret, dp(i + 1, 0) + make_pair(-pan * f + a[i], -1 * f));
return ret;
}
pair<long long, int> get(long long x) {
pan = x;
memset(vis, 0, sizeof(vis));
return dp(0, 1);
}
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 |
405 ms |
46360 KB |
Output is correct |
2 |
Correct |
403 ms |
46976 KB |
Output is correct |
3 |
Correct |
414 ms |
47184 KB |
Output is correct |
4 |
Correct |
408 ms |
47120 KB |
Output is correct |
5 |
Correct |
418 ms |
46936 KB |
Output is correct |
6 |
Correct |
417 ms |
46164 KB |
Output is correct |
7 |
Correct |
408 ms |
46384 KB |
Output is correct |
8 |
Correct |
369 ms |
46928 KB |
Output is correct |
9 |
Correct |
358 ms |
46416 KB |
Output is correct |
10 |
Correct |
361 ms |
46792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
358 ms |
46540 KB |
Output is correct |
2 |
Correct |
377 ms |
47184 KB |
Output is correct |
3 |
Correct |
406 ms |
46544 KB |
Output is correct |
4 |
Correct |
404 ms |
46932 KB |
Output is correct |
5 |
Correct |
406 ms |
46420 KB |
Output is correct |
6 |
Correct |
401 ms |
46672 KB |
Output is correct |
7 |
Correct |
416 ms |
47388 KB |
Output is correct |
8 |
Correct |
362 ms |
47172 KB |
Output is correct |
9 |
Correct |
353 ms |
46156 KB |
Output is correct |
10 |
Correct |
366 ms |
46928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
393 ms |
46932 KB |
Output is correct |
2 |
Correct |
389 ms |
49492 KB |
Output is correct |
3 |
Correct |
419 ms |
49712 KB |
Output is correct |
4 |
Correct |
439 ms |
49460 KB |
Output is correct |
5 |
Correct |
436 ms |
49748 KB |
Output is correct |
6 |
Correct |
459 ms |
50004 KB |
Output is correct |
7 |
Correct |
405 ms |
50260 KB |
Output is correct |
8 |
Correct |
391 ms |
49748 KB |
Output is correct |
9 |
Correct |
399 ms |
50260 KB |
Output is correct |
10 |
Correct |
402 ms |
50260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5976 KB |
Output is correct |
2 |
Correct |
3 ms |
5908 KB |
Output is correct |
3 |
Correct |
3 ms |
5980 KB |
Output is correct |
4 |
Correct |
3 ms |
5980 KB |
Output is correct |
5 |
Correct |
3 ms |
6104 KB |
Output is correct |
6 |
Correct |
3 ms |
5980 KB |
Output is correct |
7 |
Correct |
3 ms |
6164 KB |
Output is correct |
8 |
Correct |
3 ms |
5980 KB |
Output is correct |
9 |
Correct |
3 ms |
4700 KB |
Output is correct |
10 |
Correct |
4 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5976 KB |
Output is correct |
2 |
Correct |
3 ms |
5908 KB |
Output is correct |
3 |
Correct |
3 ms |
5980 KB |
Output is correct |
4 |
Correct |
3 ms |
5980 KB |
Output is correct |
5 |
Correct |
3 ms |
6104 KB |
Output is correct |
6 |
Correct |
3 ms |
5980 KB |
Output is correct |
7 |
Correct |
3 ms |
6164 KB |
Output is correct |
8 |
Correct |
3 ms |
5980 KB |
Output is correct |
9 |
Correct |
3 ms |
4700 KB |
Output is correct |
10 |
Correct |
4 ms |
4700 KB |
Output is correct |
11 |
Correct |
4 ms |
4696 KB |
Output is correct |
12 |
Correct |
3 ms |
5980 KB |
Output is correct |
13 |
Correct |
4 ms |
4904 KB |
Output is correct |
14 |
Correct |
4 ms |
5980 KB |
Output is correct |
15 |
Correct |
3 ms |
6196 KB |
Output is correct |
16 |
Correct |
3 ms |
5976 KB |
Output is correct |
17 |
Correct |
3 ms |
5980 KB |
Output is correct |
18 |
Correct |
4 ms |
5980 KB |
Output is correct |
19 |
Correct |
3 ms |
5980 KB |
Output is correct |
20 |
Correct |
4 ms |
4696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5976 KB |
Output is correct |
2 |
Correct |
3 ms |
5908 KB |
Output is correct |
3 |
Correct |
3 ms |
5980 KB |
Output is correct |
4 |
Correct |
3 ms |
5980 KB |
Output is correct |
5 |
Correct |
3 ms |
6104 KB |
Output is correct |
6 |
Correct |
3 ms |
5980 KB |
Output is correct |
7 |
Correct |
3 ms |
6164 KB |
Output is correct |
8 |
Correct |
3 ms |
5980 KB |
Output is correct |
9 |
Correct |
3 ms |
4700 KB |
Output is correct |
10 |
Correct |
4 ms |
4700 KB |
Output is correct |
11 |
Correct |
4 ms |
4696 KB |
Output is correct |
12 |
Correct |
3 ms |
5980 KB |
Output is correct |
13 |
Correct |
4 ms |
4904 KB |
Output is correct |
14 |
Correct |
4 ms |
5980 KB |
Output is correct |
15 |
Correct |
3 ms |
6196 KB |
Output is correct |
16 |
Correct |
3 ms |
5976 KB |
Output is correct |
17 |
Correct |
3 ms |
5980 KB |
Output is correct |
18 |
Correct |
4 ms |
5980 KB |
Output is correct |
19 |
Correct |
3 ms |
5980 KB |
Output is correct |
20 |
Correct |
4 ms |
4696 KB |
Output is correct |
21 |
Correct |
5 ms |
4956 KB |
Output is correct |
22 |
Correct |
5 ms |
4956 KB |
Output is correct |
23 |
Correct |
6 ms |
4956 KB |
Output is correct |
24 |
Correct |
5 ms |
5088 KB |
Output is correct |
25 |
Correct |
5 ms |
5164 KB |
Output is correct |
26 |
Correct |
5 ms |
6364 KB |
Output is correct |
27 |
Correct |
5 ms |
4956 KB |
Output is correct |
28 |
Correct |
5 ms |
5164 KB |
Output is correct |
29 |
Correct |
5 ms |
5084 KB |
Output is correct |
30 |
Correct |
5 ms |
6236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
405 ms |
46360 KB |
Output is correct |
2 |
Correct |
403 ms |
46976 KB |
Output is correct |
3 |
Correct |
414 ms |
47184 KB |
Output is correct |
4 |
Correct |
408 ms |
47120 KB |
Output is correct |
5 |
Correct |
418 ms |
46936 KB |
Output is correct |
6 |
Correct |
417 ms |
46164 KB |
Output is correct |
7 |
Correct |
408 ms |
46384 KB |
Output is correct |
8 |
Correct |
369 ms |
46928 KB |
Output is correct |
9 |
Correct |
358 ms |
46416 KB |
Output is correct |
10 |
Correct |
361 ms |
46792 KB |
Output is correct |
11 |
Correct |
358 ms |
46540 KB |
Output is correct |
12 |
Correct |
377 ms |
47184 KB |
Output is correct |
13 |
Correct |
406 ms |
46544 KB |
Output is correct |
14 |
Correct |
404 ms |
46932 KB |
Output is correct |
15 |
Correct |
406 ms |
46420 KB |
Output is correct |
16 |
Correct |
401 ms |
46672 KB |
Output is correct |
17 |
Correct |
416 ms |
47388 KB |
Output is correct |
18 |
Correct |
362 ms |
47172 KB |
Output is correct |
19 |
Correct |
353 ms |
46156 KB |
Output is correct |
20 |
Correct |
366 ms |
46928 KB |
Output is correct |
21 |
Correct |
393 ms |
46932 KB |
Output is correct |
22 |
Correct |
389 ms |
49492 KB |
Output is correct |
23 |
Correct |
419 ms |
49712 KB |
Output is correct |
24 |
Correct |
439 ms |
49460 KB |
Output is correct |
25 |
Correct |
436 ms |
49748 KB |
Output is correct |
26 |
Correct |
459 ms |
50004 KB |
Output is correct |
27 |
Correct |
405 ms |
50260 KB |
Output is correct |
28 |
Correct |
391 ms |
49748 KB |
Output is correct |
29 |
Correct |
399 ms |
50260 KB |
Output is correct |
30 |
Correct |
402 ms |
50260 KB |
Output is correct |
31 |
Correct |
4 ms |
5976 KB |
Output is correct |
32 |
Correct |
3 ms |
5908 KB |
Output is correct |
33 |
Correct |
3 ms |
5980 KB |
Output is correct |
34 |
Correct |
3 ms |
5980 KB |
Output is correct |
35 |
Correct |
3 ms |
6104 KB |
Output is correct |
36 |
Correct |
3 ms |
5980 KB |
Output is correct |
37 |
Correct |
3 ms |
6164 KB |
Output is correct |
38 |
Correct |
3 ms |
5980 KB |
Output is correct |
39 |
Correct |
3 ms |
4700 KB |
Output is correct |
40 |
Correct |
4 ms |
4700 KB |
Output is correct |
41 |
Correct |
4 ms |
4696 KB |
Output is correct |
42 |
Correct |
3 ms |
5980 KB |
Output is correct |
43 |
Correct |
4 ms |
4904 KB |
Output is correct |
44 |
Correct |
4 ms |
5980 KB |
Output is correct |
45 |
Correct |
3 ms |
6196 KB |
Output is correct |
46 |
Correct |
3 ms |
5976 KB |
Output is correct |
47 |
Correct |
3 ms |
5980 KB |
Output is correct |
48 |
Correct |
4 ms |
5980 KB |
Output is correct |
49 |
Correct |
3 ms |
5980 KB |
Output is correct |
50 |
Correct |
4 ms |
4696 KB |
Output is correct |
51 |
Correct |
5 ms |
4956 KB |
Output is correct |
52 |
Correct |
5 ms |
4956 KB |
Output is correct |
53 |
Correct |
6 ms |
4956 KB |
Output is correct |
54 |
Correct |
5 ms |
5088 KB |
Output is correct |
55 |
Correct |
5 ms |
5164 KB |
Output is correct |
56 |
Correct |
5 ms |
6364 KB |
Output is correct |
57 |
Correct |
5 ms |
4956 KB |
Output is correct |
58 |
Correct |
5 ms |
5164 KB |
Output is correct |
59 |
Correct |
5 ms |
5084 KB |
Output is correct |
60 |
Correct |
5 ms |
6236 KB |
Output is correct |
61 |
Correct |
462 ms |
49440 KB |
Output is correct |
62 |
Correct |
447 ms |
50436 KB |
Output is correct |
63 |
Correct |
451 ms |
49232 KB |
Output is correct |
64 |
Correct |
473 ms |
50004 KB |
Output is correct |
65 |
Correct |
443 ms |
50004 KB |
Output is correct |
66 |
Correct |
458 ms |
50028 KB |
Output is correct |
67 |
Correct |
423 ms |
49492 KB |
Output is correct |
68 |
Correct |
399 ms |
50064 KB |
Output is correct |
69 |
Correct |
384 ms |
49360 KB |
Output is correct |
70 |
Correct |
429 ms |
49232 KB |
Output is correct |