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>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;
int32_t main() {
int n, K;
cin >> n >> K;
vector<int> v(n+1);
for(int i=1; i<=n; i++) cin >> v[i];
vector<ll> pref(n+1);
for(int i=1; i<=n; i++) pref[i] = pref[i-1] + v[i];
ll dp[n+1][K+1];
int par[n+1][K+1];
memset(par, 0, sizeof(par));
memset(dp, 0, sizeof(dp));
for(int i=1; i<=n; i++) {
for(int j=1; j<=K; j++) {
for(int k=i; k>=1; k--) {
if(dp[i][j] < dp[k-1][j-1] + (pref[i] - pref[k-1]) * (pref[n] - pref[i])) {
dp[i][j] = dp[k-1][j-1] + (pref[i] - pref[k-1]) * (pref[n] - pref[i]);
par[i][j] = k-1;
}
}
}
}
int pos = 0;
for(int i=1; i<=n; i++)
if(dp[i][K] >= dp[pos][K]) pos = i;
cout << dp[pos][K] << '\n';
int curr = pos, k = K;
vector<int> ans;
while(k) {
ans.push_back(curr);
curr = par[curr][k];
if(k == 1) break;
k--;
}
reverse(all(ans));
for(int &x : ans) cout << x << " ";
return 0;
}
# | 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... |