제출 #848673

#제출 시각아이디문제언어결과실행 시간메모리
848673Darren0724등산 경로 (IZhO12_route)C++17
0 / 100
661 ms65536 KiB
#include <bits/stdc++.h> using namespace std; int32_t main() { int n,k;cin>>n>>k; vector<int> v(n); for(int i=0;i<n;i++){ cin>>v[i]; } int p=max_element(v.begin(),v.end())-v.begin(); rotate(v.begin(),v.begin()+p,v.end()); v.push_back(v[0]); set<int> s; for(int i=0;i<=n;i++){ s.insert(i); } vector<int> a; vector<pair<int,int>> b; for(int i=1;i<n;i++){ a.push_back(i); } sort(a.begin(),a.end(),[&](int a,int b){return v[a]<v[b];}); for(int j=0;j<n-1;j++){ int i=a[j]; auto it=--s.lower_bound(i); auto it1=s.upper_bound(i); b.push_back({*it1-*it-1,min(v[*it],v[*it1])-v[i]}); s.erase(i); } sort(b.begin(),b.end()); int ans=0; for(auto[p,cnt]:b){ if(p*cnt>k){ ans+=k/p; break; } ans+=cnt; k-=p*cnt; } cout<<ans*2<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...