#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
ll dp1[100001][201];
int dp2[100001][201];
int n;
ll Dat[100001];
ll f(int m, int k){
if(k+1 > n + 1 - m) return 0;
if(k == 0) return 0;
if(dp1[m][k] != -1) return dp1[m][k];
ll res = -1;
for(int i = m+1; i <= n-k+1; i++){
ll r = (Dat[i-1] - Dat[m-1])*(Dat[n] - Dat[i-1]) + f(i, k-1);
if(r >= res){
res = r;
dp2[m][k] = i;
}
if(Dat[n] - Dat[i-1] > Dat[i-1] - Dat[m-1]) break;
}
dp1[m][k] = res;
return res;
}
void solve(){
int k;
cin >> n >> k;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= k; j++){
dp1[i][j] = -1;
dp2[i][j] = -1;
}
}
Dat[0] = 0;
for(int i = 1; i <= n; i++){
cin >> Dat[i];
Dat[i] += Dat[i-1];
}
cout << f(1, k) << '\n';
int key = 1;
while(true){
key = dp2[key][k];
if(key == -1) break;
cout << key-1 << ' ';
k--;
}
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
contestant didn't find the optimal answer: 91 < 108 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
contestant didn't find the optimal answer: 60629 < 1093956 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
856 KB |
contestant didn't find the optimal answer: 201746 < 610590000 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
contestant didn't find the optimal answer: 96072 < 21503404 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
24408 KB |
contestant didn't find the optimal answer: 628910 < 1818678304 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
52 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |