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 pb push_back
#define ld long double
#define ll long long
mt19937 rnd(51);
const ll INF = 1e18;
struct line {
int x, b;
};
ld intersection(line a, line b) {
}
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LCOAL
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<ll> a(n), pr(n);
vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, -INF));
vector<vector<int>> par(n + 1, vector<int>(k + 1));
for (int i = 0; i < n; i++) {
cin >> a[i];
}
reverse(a.begin(), a.end());
for (int i = 0; i < n; i++) {
pr[i] = a[i];
if (i > 0) {
pr[i] += pr[i - 1];
}
}
for (int i = 0; i < n; i++) {
dp[i][0] = 0;
for (int j = i - 1; j >= 0; j--) {
for (int f = 1; f <= k; f++) {
if (dp[j][f - 1] - pr[j] * pr[j] + pr[i] * pr[j] > dp[i][f]) {
dp[i][f] = dp[j][f - 1] - pr[j] * pr[j] + pr[i] * pr[j];
par[i][f] = j;
}
}
}
}
cout << dp[n - 1][k] << endl;
vector<int> res;
int i = n - 1, j = k, sum = 0;
while (j > 0) {
res.pb(i - par[i][j]);
i = par[i][j];
j--;
sum += res.back();
}
int now = 0;
for (auto to : res) {
cout << (now += to) << ' ';
}
cout << endl;
return 0;
}
Compilation message (stderr)
sequence.cpp: In function 'long double intersection(line, line)':
sequence.cpp:19:1: warning: no return statement in function returning non-void [-Wreturn-type]
19 | }
| ^
# | 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... |