# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
977012 | Amaarsaa | Split the sequence (APIO14_sequence) | C++14 | 150 ms | 3932 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>
using namespace std;
using ll = long long ;
int main() {
// freopen("moocast.in", "r", stdin);
// freopen("moocast.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(NULL);
ll t, n, m, ans, s, mx, mx_cnt, sum, x, y, r, p, i, j;
cin >> n >> m;
ll a[n + 2], Sum[n + 2], Umnu[n +2], Daraa[n + 2];
Sum[0] = 0;
for (i = 1; i <= n; i ++) {
cin >> a[i];
Sum[i] = Sum[i - 1] + a[i];
}
for (i = 1; i <= n; i ++) Umnu[i] = 0, Daraa[i] = n;
ans = 0;
vector < ll > v;
for (i = 1; i <= m; i ++) {
mx_cnt = mx = -1;
for (j = 1; j <= n; j ++) {
if ( Daraa[j] == j) continue;
s = (Sum[j] - Sum[Umnu[j]]) * (Sum[Daraa[j]] - Sum[j]);
if ( s > mx_cnt) {
mx_cnt = s;
mx = j;
}
}
ans += mx_cnt;
Umnu[mx] = Daraa[mx] = mx;
v.push_back(mx);
for (j = 2; j <= n; j ++) Umnu[j] = max(Umnu[j], Umnu[j - 1]);
for (j = n - 1; j >= 1; j --) Daraa[j] = min(Daraa[j], Daraa[j + 1]);
}
cout << ans << endl;
for ( ll X : v) cout << X << " ";
cout << endl;
}
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... |