Submission #1313348

#TimeUsernameProblemLanguageResultExecution timeMemory
1313348DeepessonFeast (NOI19_feast)C++17
100 / 100
100 ms2752 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...