# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1081903 | kiethm07 | Split the sequence (APIO14_sequence) | C++11 | 2056 ms | 86748 KiB |
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 pii pair<int,int>
#define iii pair<int,pii>
#define fi first
#define se second
#define vi vector<int>
#define vii vector<pii>
#define pb(i) push_back(i)
#define all(x) x.begin(),x.end()
#define TEXT "a"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int inf = 1e9 + 7;
const ld eps = 1e-8;
const double pi = acos(-1);
const int N = 1e5 + 5;
const int K = 205;
int n,k;
ll p[N];
ll dp[N][K];
int pre[N][K];
struct line{
ll a,b;
int id;
line(ll _a, ll _b, int _id){
a = _a;
b = _b;
id = _id;
}
ll eval(ll x){
return a * x + b;
}
double isect(const line& F) const{
return 1.0 * (F.b - b) / (a - F.a);
}
};
//struct CHT{
// deque<line> dq;
// void add(line F){
// int n = dq.size();
// while(n >= 2 && ){
// n--;
// }
// }
// pair<ll,int> query()
//};
int main(){
cin.tie(0) -> sync_with_stdio(0);
if (fopen(TEXT".inp","r")){
freopen(TEXT".inp","r",stdin);
freopen(TEXT".out","w",stdout);
}
cin >> n >> k;
for (int i = 1; i <= n; i++){
cin >> p[i];
p[i] += p[i - 1];
}
for (int used = 1; used <= k; used++){
for (int i = 1; i <= n; i++){
for (int j = 0; j < i; j++){
dp[i][used] = max(dp[i][used], dp[j][used - 1] + (p[i] - p[j]) * (p[n] - p[i]));
if (dp[i][used] == dp[j][used - 1] + (p[i] - p[j]) * (p[n] - p[i])) pre[i][used] = j;
}
}
}
int best = 0;
for (int i = 1; i <= n; i++){
if (dp[i][k] >= dp[best][k]) best = i;
}
cout << dp[best][k] << "\n";
vector<int> v;
for (int used = k; used >= 1; used--){
v.push_back(best);
best = pre[best][used];
}
reverse(all(v));
for (int i : v) cout << i << " ";
return 0;
}
Compilation message (stderr)
# | 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... |