Submission #341121

#TimeUsernameProblemLanguageResultExecution timeMemory
341121juggernautMountain Trek Route (IZhO12_route)C++14
100 / 100
542 ms26152 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; priority_queue<pair<int,int>>S; int main(){ int n,k,ans=0; cin>>n>>k; vector<int>a(n); for(int i=0;i<n;i++)cin>>a[i]; rotate(a.begin(),max_element(a.begin(),a.end()),a.end()); a.push_back(a[0]); vector<int>s; for(int i=0;i<=n;i++){ while(s.size()&&a[s.back()]<a[i]){ int val=a[s.back()]; s.pop_back(); S.push({s.back()+1-i,min(a[s.back()],a[i])-val}); } s.push_back(i); } while(!S.empty()){ auto c=S.top(); S.pop(); c.first*=-1; int t=min(k/c.first,c.second); ans+=t<<1; k-=t*c.first; } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...