# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
37454 | Just_Solve_The_Problem | Split the sequence (APIO14_sequence) | C++11 | 2000 ms | 20204 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 <cstdio>
#include <vector>
using namespace std;
#define pb push_back
#define ll long long
const int N = (int)1e5 + 7;
int a[N];
ll pref[N];
ll ans = 0;
int n, k;
vector < int > anss;
int max (int a, int b) {
return (a < b) ? b : a;
}
void go (int pos, int kk, int last, ll sum, vector < int > vec = vector < int > ()) {
if (k + 1 == kk) {
if (sum > ans) {
ans = sum;
anss = vec;
}
return ;
} else if (pos == n) {
return ;
}
vec.pb(pos);
go(pos + 1, kk + 1, pos, sum + (pref[n] - pref[pos]) * (pref[pos] - pref[last]), vec);
vec.pop_back();
go(pos + 1, kk, last, sum, vec);
}
main () {
scanf ("%d %d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf ("%d", a + i);
}
for (int i = 1; i <= n; i++) {
pref[i] = pref[i - 1] + a[i];
}
go (1, 1, 0, 0);
printf ("%lld\n", ans);
for (int to : anss) {
printf ("%d ", to);
}
}
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... |