Notice
Recent Posts
문제 풀이 및 개발 공간
[백준] 11286번 절댓값 힙 (silver 1 본문
import java.io.*;
import java.util.*;
class Point{
int value;
int original;
public Point(int value, int original){
this.value=Math.abs(value);
this.original=original;
}
}
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
Queue<Point>que=new PriorityQueue<>(new Comparator<Point>(){
@Override
public int compare(Point p1,Point p2){
if(p1.value<p2.value){
return -1;
}
else if(p1.value>p2.value){
return 1;
}
else{
if(p1.original<p2.original){
return -1;
}
else if(p1.original>p2.original){
return 1;
}
return 0;
}
}
});
int n=Integer.parseInt(br.readLine());
for(int i=0; i<n; i++){
int temp=Integer.parseInt(br.readLine());
if(temp==0){
if(que.isEmpty()){
bw.write("0\n");
}
else{
bw.write(que.poll().original+"\n");
}
}
else{
que.offer(new Point(temp,temp));
}
}
bw.flush();
}
}
'백준공부 > java' 카테고리의 다른 글
[백준] 28281번 선물 (bronze 4 (0) | 2023.07.01 |
---|---|
[백준] 14235번 크리스마스 선물 (silver 3 (0) | 2023.06.27 |
[백준] 11279번 최대 힙 (silver 2 (0) | 2023.06.27 |
[백준] 1927번 최소 힙 (silver 2 (0) | 2023.06.27 |
[백준] 2018번 수들의 합 5 (silver 5 (0) | 2023.06.27 |