Submission #341121

# Submission time Handle Problem Language Result Execution time Memory
341121 2020-12-29T03:17:01 Z juggernaut Mountain Trek Route (IZhO12_route) C++14
100 / 100
542 ms 26152 KB
#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 time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 50 ms 3044 KB Output is correct
11 Correct 62 ms 3172 KB Output is correct
12 Correct 56 ms 3300 KB Output is correct
13 Correct 535 ms 26152 KB Output is correct
14 Correct 523 ms 26152 KB Output is correct
15 Correct 464 ms 24200 KB Output is correct
16 Correct 498 ms 25256 KB Output is correct
17 Correct 494 ms 25128 KB Output is correct
18 Correct 516 ms 25896 KB Output is correct
19 Correct 542 ms 26152 KB Output is correct
20 Correct 430 ms 21320 KB Output is correct