이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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
#define pv pair<ll,vector<int>>
const int N = 1005;
const int MAXN = 1e5+7;
const ll INF = 1e18;
int n, k, a[MAXN];
ll pref[MAXN];
pv dp[N][N];
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++){
cin >> a[i];
pref[i] = pref[i-1]+a[i];
}
for (int i = 2; i <= n; i++){
for (int x = 1; x <= k; x++){
// int l = 1, r = i-1;
// while(l <= r){
// int md = (l+r)/2;
// pv X = dp[md][x-1];
// X.ss.pb(md);
// dp[i][x] = max(dp[i][x], {X.ff+(pref[i]-pref[md])*pref[md], X.ss});
// if (pref[md]*pref[md]>dp[md][x-1].ff) r=md-1;
// else l=md+1;
// }
for (int j = 1; j < i; j++){
pv X = dp[j][x-1];
X.ss.pb(j);
dp[i][x] = max(dp[i][x], {X.ff+(pref[i]-pref[j])*pref[j], X.ss});
}
}
}
assert(dp[n][k].ff<=pref[n]*pref[n]);
cout << dp[n][k].ff << '\n';
for (auto i : dp[n][k].ss) 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... |