https://www.codetree.ai/missions/8/problems/min-integer-output/submissions
코드트리 | 코딩테스트 준비를 위한 알고리즘 정석
국가대표가 만든 코딩 공부의 가이드북 코딩 왕초보부터 꿈의 직장 코테 합격까지, 국가대표가 엄선한 커리큘럼으로 준비해보세요.
www.codetree.ai
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define endl '\n'
int main(){
priority_queue<ll,vector<ll>,greater<ll>> pq;
int n;
cin>>n;
for(int i=0;i<n;i++){
ll a;
cin>>a;
if(a==0){
if(pq.empty()){
cout<<0<<endl;
continue;
}
cout<<pq.top()<<endl;
pq.pop();
}else{
pq.push(a);
}
}
}
'Algorithm' 카테고리의 다른 글
[프로그래머스] 두 큐 합 같게 만들기 (0) | 2024.12.23 |
---|---|
[코드트리] 숫자 빠르게 찾기 (0) | 2024.12.20 |
[코드트리] 최소값 3개 (0) | 2024.12.19 |
[코드트리] 마지막으로 남은 숫자 (0) | 2024.12.18 |
[코드트리] 가장 가까운 점 (0) | 2024.12.17 |
https://www.codetree.ai/missions/8/problems/min-integer-output/submissions
코드트리 | 코딩테스트 준비를 위한 알고리즘 정석
국가대표가 만든 코딩 공부의 가이드북 코딩 왕초보부터 꿈의 직장 코테 합격까지, 국가대표가 엄선한 커리큘럼으로 준비해보세요.
www.codetree.ai
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define endl '\n'
int main(){
priority_queue<ll,vector<ll>,greater<ll>> pq;
int n;
cin>>n;
for(int i=0;i<n;i++){
ll a;
cin>>a;
if(a==0){
if(pq.empty()){
cout<<0<<endl;
continue;
}
cout<<pq.top()<<endl;
pq.pop();
}else{
pq.push(a);
}
}
}
'Algorithm' 카테고리의 다른 글
[프로그래머스] 두 큐 합 같게 만들기 (0) | 2024.12.23 |
---|---|
[코드트리] 숫자 빠르게 찾기 (0) | 2024.12.20 |
[코드트리] 최소값 3개 (0) | 2024.12.19 |
[코드트리] 마지막으로 남은 숫자 (0) | 2024.12.18 |
[코드트리] 가장 가까운 점 (0) | 2024.12.17 |