# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
17348 | gs14004 | 등산 경로 (IZhO12_route) | C++14 | 396 ms | 21940 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef pair<int,int> pi;
int n,k,a[1000005];
priority_queue<pi, vector<pi>, greater<pi> > pq;
stack<int> s,t;
int main(){
scanf("%d %d",&n,&k);
for (int i=0; i<n; i++) {
scanf("%d",&a[i]);
}
rotate(a, max_element(a, a+n), a+n);
a[n] = a[0];
for (int i=0; i<=n; i++) {
if(s.empty() || s.top() >= a[i]){
s.push(a[i]);
t.push(i);
}
else{
while (!s.empty() && s.top() < a[i]) {
int ptop = s.top();
s.pop();
t.pop();
pq.push(pi(i - t.top() - 1, min(s.top(), a[i]) - ptop));
// first cost로 t만큼 뽕뽑
}
s.push(a[i]);
t.push(i);
}
}
int ret = 0;
while(!pq.empty()){
pi t = pq.top();
pq.pop();
int change = min(t.second, k / t.first);
ret += change * 2;
k -= change * t.first;
}
printf("%d",ret);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |