Submission #989216

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

Compilation message (stderr)

feast.cpp:33:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   33 | main()
      | ^~~~
#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...