제출 #7932

#제출 시각아이디문제언어결과실행 시간메모리
7932gs14004수열 (APIO14_sequence)C++98
50 / 100
2000 ms83512 KiB
#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=1; i<=n; i++) {
            lint res = -1e9;
            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]);
    // dependant on J = dp[j][t-1] + a[j-1] (a[n] - a[j-1])
    // dependant on I = -a[i-1]a[n]
    // dependant on IJ = a[i-1] * a[j-1]
    // lint piv = dp[j][t-1] + (a[j-1] - a[i-1])*(a[n] - a[j-1]);
    int pos1 = 1, pos2 = k;
    while (pos2){
        printf("%d ",track[pos1][pos2]-1);
        pos1 = track[pos1][pos2];
        pos2--;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...