Submission #930165

#TimeUsernameProblemLanguageResultExecution timeMemory
930165ASN49KFeast (NOI19_feast)C++14
0 / 100
71 ms1628 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define all(x) x.begin(),x.end() const int inf=1e9; using i64=long long; int n; vector<int>a; pair<i64 , int> test(const int lambda) { pair<i64,int>sol={0,0}; pair<i64,int> last={-2*inf,0}; for(int i=0;i<n;i++) { if(sol.first-lambda > last.first || (sol.first-lambda == last.first && sol.second<last.second)) { last={sol.first+a[i]-lambda, sol.second+1}; } else { last.first+=a[i]; } if(sol.first<last.first || (sol.first==last.first && sol.second>last.second)) { sol=last; } } return sol; } int main() { ios::sync_with_stdio(false); cin.tie(0); int k; cin>>n>>k; a.resize(n); int sum=0,cnt=0; for(int i=0;i<n;i++) { cin>>a[i]; if(a[i]>0)sum+=a[i],cnt++; } if(cnt <= k) { cout<<sum; return 0; } int st=0,dr=inf; i64 rez=-inf; while(st<=dr) { int m=(st+dr)/2; auto xd=test(m); if(xd.second < k) { dr=m-1; } else { st=m+1; rez=xd.first+1LL*k*m; } } cout<<rez; return 0; }
#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...