[백준] 2075. N번째 큰 수

고재욱·2021년 10월 6일

Baekjoon

목록 보기
24/35

❓ 문제 ❓
N번째 큰 수

💯 문제 풀이 💯
우선순위 큐로 모든 수를 입력 받고 큐의 크기가 n보다 커지면 pop한 후 마지막에 가장 top에 있는것이 정답이다.

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n; cin >> n;
	priority_queue<int> pq;
	for (int i = 0; i < n * n; i++) {
		int tmp;
		cin >> tmp;
		pq.push(-tmp);
		if (pq.size() > n) {
			pq.pop();
		}
	}
	cout << -pq.top();
}

0개의 댓글