#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long lint;
int n,k;
lint dp[100005][2],a[100005];
int track[100005][205];
int main(){
int t;
scanf("%d %d",&n,&k);
for (int i=0; i<n; i++) {
scanf("%d",&t);
a[i+1] = a[i] + t;
}
for (int t=1; t<=k; t++) {
for (int i=n; i>=1; i--) {
lint res = 0;
for (int j=i+1; j<=n; j++) {
lint piv = dp[j][(t-1)%2] + (a[j-1] - a[i-1])*(a[n] - a[j-1]);
if(res < piv){
res = piv;
track[i][t] = j;
}
}
dp[i][t%2] = res;
}
}
printf("%lld\n",dp[1][k%2]);
int pos1 = 1, pos2 = k;
for (int i=0; i<k; i++) {
printf("%d ",track[pos1][pos2]-1);
pos1 = track[pos1][pos2];
pos2--;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
83512 KB |
Output is correct - contestant found the optimal answer: 108 == 108 |
2 |
Correct |
0 ms |
83512 KB |
Output is correct - contestant found the optimal answer: 999 == 999 |
3 |
Incorrect |
0 ms |
83512 KB |
Output isn't correct - Integer -1 violates the range [1, 1] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |