# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
254547 | babo | Split the sequence (APIO14_sequence) | C++14 | 11 ms | 2844 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 L long long
using namespace std;
L n,k;
L a[1000010],nu[1000010];
L cut[1000010];
bool ok(L now){
return cut[now]+1!=cut[now+1]&&
(nu[cut[now]]-nu[cut[now-1]])*(nu[cut[now+1]]-nu[cut[now]])
<(nu[cut[now]+1]-nu[cut[now-1]])*(nu[cut[now+1]]-nu[cut[now]+1]);
}
void dfs(L now){
if(now==k) return;
dfs(now+1);
while(ok(now))
{
cut[now]++;
dfs(now+1);
}
}
int main()
{
scanf("%lld %lld",&n,&k);
k++;
L i;
for(i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
nu[i]=a[i]+nu[i-1];
cut[i]=i;
}
cut[k]=n;
dfs(1);
L ans=nu[n]*nu[n];
for(i=1;i<=k;i++)
ans-=(nu[cut[i]]-nu[cut[i-1]])*(nu[cut[i]]-nu[cut[i-1]]);
ans/=2;
printf("%lld\n",ans);
for(i=1;i<k;i++)
printf("%lld ",cut[i]);
}
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... |