#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
int dp[100001][202], a[100001], n, m;
int par[100001][202];
void solve () {
cin >> n >> m; m++;
for (int i = 1; i <= n; i++) {
cin >> a[i]; a[i] += a[i - 1];
}
memset(par, -1, sizeof(par));
for (int i = 1; i <= n; i++) {
dp[i][0] = -inf;
}
auto f = [&] (int l, int r) -> int {
return (a[r] - a[l - 1]) * a[l - 1];
};
for (int j = 1; j <= m; j++) {
for (int i = 0; i < j; i++) {
dp[i][j] = -inf;
}
for (int i = j; i <= n; i++) {
dp[i][j] = -inf;
for (int k = i - 1; k >= 0; k--) {
int x = dp[k][j - 1] + f(k + 1, i);
if (x > dp[i][j]) {
dp[i][j] = x;
par[i][j] = k;
}
}
}
}
cout << dp[n][m] << '\n';
vector <int> u;
int t = n, c = m;
while (true) {
if (par[t][c] == -1) {
break;
}
u.push_back(par[t][c]);
t = par[t][c]; c--;
}
u.pop_back();
reverse(u.begin(), u.end());
for (auto i : u) cout << i << " ";
cout << '\n';
}
signed main () {
ios::sync_with_stdio(0); cin.tie(0);
int tc = 1; //cin >> tc;
while (tc--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
80476 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Correct |
8 ms |
80596 KB |
contestant found the optimal answer: 999 == 999 |
3 |
Correct |
8 ms |
80528 KB |
contestant found the optimal answer: 0 == 0 |
4 |
Correct |
8 ms |
80476 KB |
contestant found the optimal answer: 1542524 == 1542524 |
5 |
Incorrect |
9 ms |
80592 KB |
Unexpected end of file - int32 expected |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
80476 KB |
contestant found the optimal answer: 1093956 == 1093956 |
2 |
Correct |
8 ms |
80600 KB |
contestant found the optimal answer: 302460000 == 302460000 |
3 |
Incorrect |
8 ms |
80476 KB |
Unexpected end of file - int32 expected |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
80472 KB |
contestant found the optimal answer: 610590000 == 610590000 |
2 |
Correct |
9 ms |
80476 KB |
contestant found the optimal answer: 311760000 == 311760000 |
3 |
Incorrect |
11 ms |
80600 KB |
Unexpected end of file - int32 expected |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
82524 KB |
contestant found the optimal answer: 21503404 == 21503404 |
2 |
Correct |
10 ms |
82520 KB |
contestant found the optimal answer: 140412195 == 140412195 |
3 |
Incorrect |
102 ms |
82704 KB |
Unexpected end of file - int32 expected |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
233 ms |
88880 KB |
contestant found the optimal answer: 1818678304 == 1818678304 |
2 |
Correct |
214 ms |
88664 KB |
contestant found the optimal answer: 1326260195 == 1326260195 |
3 |
Execution timed out |
2021 ms |
88920 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
18 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |