이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 100100;
const ll INF = 1e16;
ll dp[210][MAXN];
int pr[210][MAXN];
int n, k;
ll a[MAXN], pref[MAXN];
int main()
{
FAST_IO;
cin >> n >> k;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, n) pref[i] = pref[i-1] + a[i];
dp[0][0] = 0;
FOR(i, 1, n) dp[0][i] = -INF;
FOR(g, 1, k+1) FOR(i, 1, n) FOR(j, 0, i-1) {
ll k = pref[j];
ll b = dp[g-1][j] - pref[j] * pref[j];
ll x = pref[i];
ll cr = k*x + b;
if (cr > dp[g][i]) {
dp[g][i] = k * x + b;
pr[g][i] = j;
}
}
cout << dp[k+1][n] << "\n";
int g = k+1, i = n;
while (g > 0) {
i = pr[g][i];
g--;
if (i > 0) cout << i << " ";
}
cout << "\n";
return 0;
}
/*
7 3
4 1 3 4 0 2 3
*/
# | 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... |