이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
using namespace std;
const ll N = 1e3 + 10;
ll n, k;
ll a[N];
ll dp[N][201], pr[N][201];
int main() {
speed;
cin >> n >> k;
for(int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
dp[0][0] = 0;
for(int j = 1; j <= n; j++) {
for(int p = k; p >= 1; p--) {
for(int i = j; i > p; i--) {
if(dp[j][p] < dp[i - 1][p - 1] + (a[j] - a[i - 1]) * a[i - 1])
dp[j][p] = max(dp[j][p], dp[i - 1][p - 1] + (a[j] - a[i - 1]) * a[i - 1]),
pr[j][p] = i;
}
}
}
cout << dp[n][k] << '\n';
vector<ll> vost;
ll x = n, y = k;
while(y) {
x = pr[x][y];
y--;
vost.pb(x);
x--;
}
reverse(vost.begin(), vost.end());
for(auto u : vost)
cout << u - 1 << " ";
}
/*
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... |