# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40503 | mohammad_kilani | Split the sequence (APIO14_sequence) | C++14 | 40 ms | 24300 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define oo 1000000000
const double PI = acos(-1);
const int N = 10010 , K = 201;
int arr[N] , n , k , a , b , low , high , best[N][K];
long long dp[N][K] , sum[N] , cur1 , cur2 ;
int main(){
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++){
scanf("%d",&arr[i]);
sum[i+1] = sum[i] + arr[i];
}
for(int i=0;i<k;i++){
dp[n-1][i] = -1e17;
best[n-1][i] = n - 1;
}
best[n-1][k] = n - 1;
for(int i=n-2;i>=0;i--){
for(int j=0;j<k;j++){
a = i + 1;
dp[i][j] = dp[a][j+1] + (sum[a] - sum[i]) * (sum[n] - sum[a]);
best[i][j] = a;
a = best[i+1][j];
while(a > i){
cur1 = dp[a][j+1] + (sum[a] - sum[i]) * (sum[n] - sum[a]);
if(cur1 >= dp[i][j]){
dp[i][j] = cur1;
best[i][j] = a;
}
else
break;
a--;
}
}
}
printf("%lld\n",dp[0][0]);
int idx = 0;
for(int i=0;i<k;i++){
if(i > 0) putchar(' ');
printf("%d",best[idx][i]);
idx = best[idx][i];
}
puts("");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |