제출 #837885

#제출 시각아이디문제언어결과실행 시간메모리
837885Ahmed57Feast (NOI19_feast)C++17
100 / 100
796 ms18764 KiB
#include<bits/stdc++.h> using namespace std; long long n,k; long long arr[300001]; pair<long long,long long> check(long long x){ priority_queue<pair<long long,long long>> q; q.push({0,0}); pair<long long,long long> ans = {0,0}; for(int i = 0;i<n;i++){ long long val = arr[i]+q.top().first-x; long long sec = (q.top().second)+1; pair<long long,long long> fawzya = {val,sec}; ans = max(ans,fawzya); fawzya = ans; q.push({(-arr[i])+fawzya.first,fawzya.second}); ans = max(ans,make_pair(fawzya.first,fawzya.second)); } return ans; } int main(){ cin>>n>>k; long long ans = 0; for(int i = 0;i<n;i++){ cin>>arr[i]; if(arr[i]>0)ans+=arr[i]; if(i)arr[i]+=arr[i-1]; } long long l = 0 , r = 1e16; while(l<=r){ long long mid = (l+r)/2; pair<long long ,long long> an = check(mid); if(an.second>=k){ ans =an.first+k*mid; l = mid+1; }else { r = mid-1; } } cout<<ans<<endl; 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...