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 f0(i, n) for(int i(0); i < (n); i++)
#define f1(i, n) for(int i(1); i <= n; i++)
using namespace std;
typedef long long ll;
const int N = 100002;
int n, a[N], k, pos[N][202];
ll f[N][202], t[N];
int main(){
ios_base::sync_with_stdio(0);
cin >> n >> k;
f1(i, n) cin >> a[i];
f1(i, n) t[i] = t[i - 1] + a[i];
f1(i, n){
f[i][0] = (t[i])*1ll*(t[n] - t[i]);
for(int j = 1; j < i; j++){
if(j > k) break;
for(int x = i - 1; x >= 1; x--){
/// f[x][j - 1]
if(x > j - 1){
ll cur = f[x][j - 1] + (t[i] - t[x])*(t[n] - t[i]);
f[i][j] = max(f[i][j], cur);
if(cur == f[i][j]){
pos[i][j] = x;
}
}
else break;
}
}
}
cout << f[n][k] << endl;
int now = pos[n][k];
while(k--){
cout << now << " ";
now = pos[now][k];
}
}
# | 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... |