/*
** TASK:
** LINK:
*/
#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll, ll>
#define st first
#define nd second
#define file "test"
using namespace std;
const long long INF = 1e18;
const long long N = 200 + 5;
ll n, a[N], k, dp[N][N][N], f[N], trace[N][N][N], num[N][N][N];
ll cal(int l, int r, int cur) {
if (l == r || cur == 0) return 0;
if (dp[l][r][cur] != -1) return dp[l][r][cur];
ll &ans = dp[l][r][cur];
ans = 0;
for (int i = l; i <= r; i ++) {
for (int j = 0; j <= i - l; j ++)
if (j < cur && r - i > cur - j - 1) {
ll tmp = (f[i] - f[l - 1]) * (f[r] - f[i]) + cal(l, i, j) + cal(i + 1, r, cur - j - 1);
if (tmp >= ans)
trace[l][r][cur] = i, num[l][r][cur] = j, ans = tmp;
}
}
return ans;
}
void go(int l, int r, int cur) {
if (trace[l][r][cur] == 0 || cur == 0) return;
cout << trace[l][r][cur] << ' ';
go(l, trace[l][r][cur], num[l][r][cur]);
go(trace[l][r][cur] + 1, r, cur - num[l][r][cur] - 1);
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
// #endif
cin >> n >> k;
for (int i = 1; i <= n; i ++)
cin >> a[i], f[i] = f[i - 1] + a[i];
memset(dp, -1, sizeof dp);
cout << cal(1, n, k) << '\n';
go(1, n, k);
return 0;
}
/** /\_/\
* (= ._.)
* / >🍵 \>🍮
**/
Compilation message
sequence.cpp:61:9: warning: "/*" within comment [-Wcomment]
61 | /** /\_/\
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
67796 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Correct |
32 ms |
67832 KB |
contestant found the optimal answer: 999 == 999 |
3 |
Correct |
27 ms |
67668 KB |
contestant found the optimal answer: 0 == 0 |
4 |
Correct |
34 ms |
67864 KB |
contestant found the optimal answer: 1542524 == 1542524 |
5 |
Correct |
30 ms |
67916 KB |
contestant found the optimal answer: 4500000000 == 4500000000 |
6 |
Correct |
27 ms |
67660 KB |
contestant found the optimal answer: 1 == 1 |
7 |
Correct |
26 ms |
67668 KB |
contestant found the optimal answer: 1 == 1 |
8 |
Correct |
27 ms |
67660 KB |
contestant found the optimal answer: 1 == 1 |
9 |
Correct |
26 ms |
67924 KB |
contestant found the optimal answer: 100400096 == 100400096 |
10 |
Correct |
28 ms |
67944 KB |
contestant found the optimal answer: 900320000 == 900320000 |
11 |
Correct |
27 ms |
67928 KB |
contestant found the optimal answer: 3698080248 == 3698080248 |
12 |
Correct |
32 ms |
67916 KB |
contestant found the optimal answer: 3200320000 == 3200320000 |
13 |
Correct |
25 ms |
67852 KB |
contestant found the optimal answer: 140072 == 140072 |
14 |
Correct |
31 ms |
67788 KB |
contestant found the optimal answer: 376041456 == 376041456 |
15 |
Correct |
27 ms |
67856 KB |
contestant found the optimal answer: 805 == 805 |
16 |
Correct |
26 ms |
67924 KB |
contestant found the optimal answer: 900189994 == 900189994 |
17 |
Correct |
25 ms |
67892 KB |
contestant found the optimal answer: 999919994 == 999919994 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
71892 KB |
contestant found the optimal answer: 1093956 == 1093956 |
2 |
Correct |
28 ms |
71936 KB |
contestant found the optimal answer: 302460000 == 302460000 |
3 |
Correct |
27 ms |
71940 KB |
contestant found the optimal answer: 122453454361 == 122453454361 |
4 |
Correct |
28 ms |
71872 KB |
contestant found the optimal answer: 93663683509 == 93663683509 |
5 |
Correct |
42 ms |
71904 KB |
contestant found the optimal answer: 1005304678 == 1005304678 |
6 |
Correct |
40 ms |
71880 KB |
contestant found the optimal answer: 933702 == 933702 |
7 |
Correct |
46 ms |
71948 KB |
contestant found the optimal answer: 25082842857 == 25082842857 |
8 |
Correct |
34 ms |
71880 KB |
contestant found the optimal answer: 687136 == 687136 |
9 |
Correct |
31 ms |
71912 KB |
contestant found the optimal answer: 27295930079 == 27295930079 |
10 |
Correct |
37 ms |
71888 KB |
contestant found the optimal answer: 29000419931 == 29000419931 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
130 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
67788 KB |
declared answer doesn't correspond to the split scheme: declared = 48, real = 96072 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
29 ms |
67756 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
33 ms |
67668 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |