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 MAX 505000
int N,K;
long long array[MAX];
typedef std::pair<long long,long long> pll;
pll func(long long C){
long long a=1,b=0;
long long max=0,maxval=0;
long long pega=-C,npega=0;
for(int i=0;i!=N;++i){
pega+=array[i];
if(pega>npega){
npega=pega;
b=a;
}
if(npega-C>pega){
pega=npega-C;
a=b;
++a;
}
if(pega>max){
max=pega;
maxval=a;
}
}
return {max,maxval};
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
std::cin>>N>>K;
for(int i=0;i!=N;++i)std::cin>>array[i];
long long l=0,r=1LL<<50LL;
while(l<r){
long long m = (l+r)/2;
long long res = func(m).second;
if(res<=K){
r=m;
}else l=m+1;
}
auto res = func(l);
if(!l){
std::cout<<res.first<<"\n";
return 0;
}
std::cout<<(res.first+(K*l))<<"\n";
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |