# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1085896 |
2024-09-09T02:37:01 Z |
Persia |
Feast (NOI19_feast) |
C++14 |
|
137 ms |
262144 KB |
#include <bits/stdc++.h>
#define rep(i, l, r) for(int i = l; i <= r; i++)
#define rep2(i, l, r) for(int i = l; i >= r; i--)
#define fi first
#define se second
#define bit(i, x) (x >> i & 1)
using namespace std;
const int N = 3e5 + 3;
const int mod = 1e9 + 7;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rnd(long long l, long long r) {
return uniform_int_distribution<long long>(l, r)(rng);
}
int n, k, a[N];
long long p[N];
namespace sub1{
long long sol() {
vector<vector<long long>> dp(n + 3, vector<long long>(k + 3, 0));
vector<vector<long long>> mx(n + 3, vector<long long>(k + 3, 0));
rep(i, 1, n) {
rep(j, 1, k) {
dp[i][j] = max(dp[i - 1][j], mx[i - 1][j - 1] + p[i]);
dp[i][j] = max(dp[i][j], dp[i][j - 1]);
// rep(l, 0, i - 1) {
// dp[i][j] = max(dp[i][j], dp[l][j - 1] + p[i] - p[l]);
// }
}
mx[i][0] = max(mx[i - 1][0], -p[i]);
rep(j, 1, k - 1) {
mx[i][j] = max(mx[i - 1][j], dp[i][j] - p[i]);
}
}
// rep(i, 1, n) {
// rep(j, 1, k) cout << dp[i][j] << " ";
// cout << "\n";
// }
return dp[n][k];
}
}
int main(int argc, char* argv[]) {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("testing.txt", "r", stdin);
// freopen("outputing.txt", "w", stdout);
cin >> n >> k;
rep(i, 1, n) {
cin >> a[i];
p[i] = p[i - 1] + a[i];
}
// rep(i, 1, n) cout << p[i] << " ";
cout << sub1::sol();
// sub1::sol();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
137 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
46160 KB |
Output is correct |
2 |
Correct |
47 ms |
47184 KB |
Output is correct |
3 |
Correct |
46 ms |
46184 KB |
Output is correct |
4 |
Runtime error |
128 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
48716 KB |
Output is correct |
2 |
Correct |
56 ms |
48136 KB |
Output is correct |
3 |
Correct |
56 ms |
48464 KB |
Output is correct |
4 |
Correct |
60 ms |
48136 KB |
Output is correct |
5 |
Correct |
81 ms |
48440 KB |
Output is correct |
6 |
Correct |
60 ms |
48720 KB |
Output is correct |
7 |
Correct |
57 ms |
48980 KB |
Output is correct |
8 |
Correct |
57 ms |
48464 KB |
Output is correct |
9 |
Correct |
61 ms |
48984 KB |
Output is correct |
10 |
Correct |
57 ms |
48864 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 |
0 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 |
0 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 |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
664 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
472 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
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 |
0 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 |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
664 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
472 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
6744 KB |
Output is correct |
22 |
Correct |
28 ms |
51804 KB |
Output is correct |
23 |
Correct |
7 ms |
12380 KB |
Output is correct |
24 |
Correct |
4 ms |
7256 KB |
Output is correct |
25 |
Correct |
7 ms |
9820 KB |
Output is correct |
26 |
Correct |
4 ms |
5980 KB |
Output is correct |
27 |
Correct |
5 ms |
9560 KB |
Output is correct |
28 |
Correct |
1 ms |
1496 KB |
Output is correct |
29 |
Correct |
1 ms |
1532 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
137 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |