# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
848673 | Darren0724 | Mountain Trek Route (IZhO12_route) | C++17 | 661 ms | 65536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |