# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
847566 |
2023-09-10T01:28:22 Z |
BamshooT |
Feast (NOI19_feast) |
C++14 |
|
118 ms |
14584 KB |
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <cstdlib>
#define ll long long
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define inf -1e18
#define fi first
#define se second
using namespace std;
typedef pair <ll, int> li;
const int N = 3e5 + 9, M = 2e3 + 9;
int n, k;
ll a[N], pre[N], dp[M][M];
void sub1(){
for (int i = 1; i <= k; ++i){
ll cur = 0;
for (int j = 1; j <= n; ++j) {
cur = max(cur, dp[i-1][j] - pre[j]);
dp[i][j] = max(dp[i][j-1], cur + pre[j]);
}
}
cout << dp[k][n];
}
pair<ll, int> f[N];
void maximize(li &a, li b){
if (a.fi < b.fi) a = b;
if (a.fi == b.fi && a.se > b.se) a = b;
}
li calc(ll cost){
li best = {0, 0};
for (int i = 1; i <= n; ++i) {
f[i] = f[i-1];
maximize(f[i], {pre[i] + best.fi - cost , best.se + 1});
maximize(best, {f[i].fi - pre[i], f[i].se});
}
//f[n].se *= -1;
return f[n];
}
/// code WA
void sub2(){
ll lo = -1e18, hi = 1e18, ans = 0;
while (lo <= hi) {
ll mid = lo + hi >> 1;
li tmp = calc(mid);
if (tmp.se <= k) {
hi = mid - 1;
ans = max(ans, tmp.fi + mid*tmp.se);
} else lo = mid + 1;
}
cout << ans;
}
/// code AC
//void sub2(){
// ll lo = -1e18, hi = 1e18, ans = 0;
// while (lo < hi) {
// ll mid = lo + hi >> 1;
// li tmp = calc(mid);
// if (tmp.se <= k) {
// hi = mid;
// } else lo = mid + 1;
// }
// li tmp = calc(lo);
// cout << tmp.fi + k*lo;
//}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("nhap.inp", "r", stdin);
// freopen("xuat.out", "w", stdout);
cin >> n >> k;
FOR(i, 1, n) {
cin >> a[i];
pre[i] = pre[i-1] + a[i];
}
// if (max(k, n) <= 2000) sub1(); else
sub2();
return 0;
}
Compilation message
feast.cpp: In function 'void sub2()':
feast.cpp:55:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | ll mid = lo + hi >> 1;
| ~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
14196 KB |
Output is correct |
2 |
Correct |
63 ms |
13904 KB |
Output is correct |
3 |
Correct |
61 ms |
14020 KB |
Output is correct |
4 |
Correct |
63 ms |
13912 KB |
Output is correct |
5 |
Correct |
63 ms |
13904 KB |
Output is correct |
6 |
Correct |
62 ms |
14160 KB |
Output is correct |
7 |
Correct |
62 ms |
14168 KB |
Output is correct |
8 |
Correct |
63 ms |
13904 KB |
Output is correct |
9 |
Correct |
65 ms |
14220 KB |
Output is correct |
10 |
Correct |
52 ms |
13904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
12532 KB |
Output is correct |
2 |
Correct |
54 ms |
12608 KB |
Output is correct |
3 |
Correct |
49 ms |
12368 KB |
Output is correct |
4 |
Correct |
54 ms |
12376 KB |
Output is correct |
5 |
Correct |
52 ms |
14160 KB |
Output is correct |
6 |
Correct |
51 ms |
12380 KB |
Output is correct |
7 |
Correct |
55 ms |
12376 KB |
Output is correct |
8 |
Correct |
55 ms |
14160 KB |
Output is correct |
9 |
Correct |
53 ms |
14160 KB |
Output is correct |
10 |
Correct |
56 ms |
12368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
14160 KB |
Output is correct |
2 |
Correct |
82 ms |
13904 KB |
Output is correct |
3 |
Correct |
82 ms |
14192 KB |
Output is correct |
4 |
Correct |
81 ms |
14152 KB |
Output is correct |
5 |
Correct |
91 ms |
14160 KB |
Output is correct |
6 |
Correct |
84 ms |
14416 KB |
Output is correct |
7 |
Correct |
82 ms |
14164 KB |
Output is correct |
8 |
Correct |
81 ms |
14196 KB |
Output is correct |
9 |
Correct |
94 ms |
14264 KB |
Output is correct |
10 |
Correct |
83 ms |
14252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2400 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2400 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
2 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2392 KB |
Output is correct |
25 |
Correct |
1 ms |
2392 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
14196 KB |
Output is correct |
2 |
Correct |
63 ms |
13904 KB |
Output is correct |
3 |
Correct |
61 ms |
14020 KB |
Output is correct |
4 |
Correct |
63 ms |
13912 KB |
Output is correct |
5 |
Correct |
63 ms |
13904 KB |
Output is correct |
6 |
Correct |
62 ms |
14160 KB |
Output is correct |
7 |
Correct |
62 ms |
14168 KB |
Output is correct |
8 |
Correct |
63 ms |
13904 KB |
Output is correct |
9 |
Correct |
65 ms |
14220 KB |
Output is correct |
10 |
Correct |
52 ms |
13904 KB |
Output is correct |
11 |
Correct |
55 ms |
12532 KB |
Output is correct |
12 |
Correct |
54 ms |
12608 KB |
Output is correct |
13 |
Correct |
49 ms |
12368 KB |
Output is correct |
14 |
Correct |
54 ms |
12376 KB |
Output is correct |
15 |
Correct |
52 ms |
14160 KB |
Output is correct |
16 |
Correct |
51 ms |
12380 KB |
Output is correct |
17 |
Correct |
55 ms |
12376 KB |
Output is correct |
18 |
Correct |
55 ms |
14160 KB |
Output is correct |
19 |
Correct |
53 ms |
14160 KB |
Output is correct |
20 |
Correct |
56 ms |
12368 KB |
Output is correct |
21 |
Correct |
82 ms |
14160 KB |
Output is correct |
22 |
Correct |
82 ms |
13904 KB |
Output is correct |
23 |
Correct |
82 ms |
14192 KB |
Output is correct |
24 |
Correct |
81 ms |
14152 KB |
Output is correct |
25 |
Correct |
91 ms |
14160 KB |
Output is correct |
26 |
Correct |
84 ms |
14416 KB |
Output is correct |
27 |
Correct |
82 ms |
14164 KB |
Output is correct |
28 |
Correct |
81 ms |
14196 KB |
Output is correct |
29 |
Correct |
94 ms |
14264 KB |
Output is correct |
30 |
Correct |
83 ms |
14252 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
1 ms |
2392 KB |
Output is correct |
36 |
Correct |
1 ms |
2392 KB |
Output is correct |
37 |
Correct |
1 ms |
2392 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2392 KB |
Output is correct |
40 |
Correct |
1 ms |
2392 KB |
Output is correct |
41 |
Correct |
1 ms |
2392 KB |
Output is correct |
42 |
Correct |
1 ms |
2392 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
2392 KB |
Output is correct |
46 |
Correct |
1 ms |
2400 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
1 ms |
2392 KB |
Output is correct |
49 |
Correct |
1 ms |
2392 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
2 ms |
2392 KB |
Output is correct |
52 |
Correct |
1 ms |
2392 KB |
Output is correct |
53 |
Correct |
1 ms |
2392 KB |
Output is correct |
54 |
Correct |
1 ms |
2392 KB |
Output is correct |
55 |
Correct |
1 ms |
2392 KB |
Output is correct |
56 |
Correct |
1 ms |
2396 KB |
Output is correct |
57 |
Correct |
1 ms |
2396 KB |
Output is correct |
58 |
Correct |
1 ms |
2392 KB |
Output is correct |
59 |
Correct |
1 ms |
2392 KB |
Output is correct |
60 |
Correct |
1 ms |
2392 KB |
Output is correct |
61 |
Correct |
112 ms |
14404 KB |
Output is correct |
62 |
Correct |
81 ms |
14416 KB |
Output is correct |
63 |
Correct |
91 ms |
14384 KB |
Output is correct |
64 |
Correct |
113 ms |
14416 KB |
Output is correct |
65 |
Correct |
118 ms |
14584 KB |
Output is correct |
66 |
Correct |
112 ms |
14472 KB |
Output is correct |
67 |
Correct |
111 ms |
14196 KB |
Output is correct |
68 |
Correct |
83 ms |
14276 KB |
Output is correct |
69 |
Correct |
81 ms |
14160 KB |
Output is correct |
70 |
Correct |
81 ms |
14356 KB |
Output is correct |