백준 1927번(Java)

박은지·2025년 4월 16일
0

백준

목록 보기
61/89
post-thumbnail

import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PriorityQueue<Integer> queue = new PriorityQueue<>();
		
		int N = Integer.parseInt(br.readLine());
		
		for(int i=0; i<N; i++) {
			int temp = Integer.parseInt(br.readLine());
			
			if(temp == 0) {
				if(queue.isEmpty()) {
					System.out.println("0");
				}
				else {
					System.out.println(queue.poll());
				}
			}
			else {
				queue.add(temp);
			}
		}
	}
}
profile
백엔드 개발자가 되고싶은 eunzi😊

0개의 댓글