# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1113881 | Tsagana | Mountain Trek Route (IZhO12_route) | C++14 | 180 ms | 28420 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>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define lnl long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
using namespace std;
void solve () {
int n, k; cin >> n >> k;
vector<int>a(n);
for (auto &i: a) cin >> i;
rotate(a.begin(), max_element(all(a)), a.end());
a.pb(a[0]);
pq<pair<int, int>> q;
vector<int> s;
for (int i = 0; i <= n; i++) {
while (s.size() && a[s.back()] < a[i]) {
int val = a[s.back()];
s.pp();
q.push({s.back()+1-i, min(a[s.back()], a[i])-val});
}
s.pb(i);
}
int ans = 0;
while (!q.empty()){
pair<int, int> i = q.top(); q.pop();
i.F *= -1;
int l = min(k/i.F, i.S);
ans += l*2;
k -= l*i.F;
}
cout << ans;
}
int main() {IOS solve(); return 0;}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |