#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N = 1e5 + 5;
ll a[N], dp[N][205], par[N][205];
int n, k;
ll sum (int x, int y) {
ll ret = 0;
for (int i = x; i <= y; ++i) {
ret += a[i];
}
return ret;
}
int main () {
// freopen ("sequence.in", "r", stdin);
// freopen ("sequence.out", "w", stdout);
// freopen ("input.txt", "r", stdin);
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
reverse (a + 1,a + n + 1);
// dp[i][j] i-cenli j grupba bolemde maximum value.
for (int i = 2; i <= n; ++i) {
for (int x = 2; x <= min (i, k + 1); ++x) {
for (int j = x - 1; j < i; ++j) {
// dp[i][x] = max (dp[i][x], dp[j][x - 1] + sum (j + 1, i) * sum (1, j));
ll val = dp[j][x - 1] + sum (j + 1, i) * sum (1, j);
if (dp[i][x] < val) {
par[i][x] = j;
dp[i][x] = val;
}
}
}
}
vector <int> cyk;
int y = k + 1, x = n;
while (1) {
x = par[x][y];
if (!x) break;
cyk.pb (x);
}
cout << dp[n][k + 1] << "\n";
for (int i : cyk) {
// cout << n - i - 1<< " ";
cout << n - i << " ";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Correct |
0 ms |
440 KB |
contestant found the optimal answer: 999 == 999 |
3 |
Incorrect |
0 ms |
348 KB |
Unexpected end of file - int32 expected |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
declared answer doesn't correspond to the split scheme: declared = 1093956, real = 794349 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2908 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
439 ms |
4072 KB |
declared answer doesn't correspond to the split scheme: declared = 21503404, real = 15681357 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2040 ms |
7500 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2054 ms |
8036 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |