SWEA 2930 힙

1 개요[ | ]

SWEA 2930 힙
SW Expert 아카데미
# 문제 풀이

틀:SWEA 난이도 3-5

2 C++[ | ]

3 Java[ | ]

import java.util.*;
public class Solution {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(Collections.reverseOrder());
		for(int tc=1; tc<=T; tc++) {
			sb.append("#");
			sb.append(tc);
			pq.clear();
			int N = sc.nextInt();
			for(int n=0; n<N; n++) {
				int operation = sc.nextInt();
				if( operation == 1) {
					pq.add(sc.nextInt());
					continue;
				}
				if( pq.isEmpty() ) {
					sb.append(" -1");
					continue;
				}
				sb.append(" ");
				sb.append(pq.poll());
			}
			sb.append("\n");
		}
		System.out.print(sb);
		sc.close();
	}
}

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}