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 wr cout << "Continue debugging\n";
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second
const int N = 1005;
const int MAXN = 1e5+5;
int n, k;
ll pref[MAXN], dp[N][205];
vector<int> E[N][205];
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++){
int x;
cin >> x;
pref[i] = pref[i-1]+x;
}
for (int i = 2; i <= n; i++){
for (int x = 1; x <= k; x++){
int pos = 0;
for (int j = 1; j < i; j++){
ll cur = dp[j][x-1]+(pref[i]-pref[j])*pref[j];
if (dp[i][x] <= cur){
dp[i][x] = cur;
pos = j;
}
}
E[i][x].insert(E[i][x].end(), all(E[pos][x-1]));
E[i][x].pb(pos);
}
}
cout << dp[n][k] << '\n';
for (auto i : E[n][k]) cout << i << " ";
}
# | 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... |