끄적끄적
백준 [2075] N번째 큰 수 본문
출처 : https://www.acmicpc.net/problem/2075
2075번: N번째 큰 수
첫째 줄에 N(1 ≤ N ≤ 1,500)이 주어진다. 다음 N개의 줄에는 각 줄마다 N개의 수가 주어진다. 표에 적힌 수는 -10억보다 크거나 같고, 10억보다 작거나 같은 정수이다.
www.acmicpc.net
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<queue> | |
using namespace std; | |
int main() { | |
ios::sync_with_stdio(false); | |
cin.tie(0); | |
cout.tie(0); | |
int N, tmp; | |
priority_queue<int, vector<int>, greater<int>> pq; //오름차순 | |
cin >> N; | |
for (int i = 0; i < N; i++) { | |
for (int j = 0; j < N; j++) { | |
cin >> tmp; | |
pq.push(tmp); | |
if (pq.size() > N) { | |
pq.pop(); | |
} | |
} | |
} | |
cout << pq.top() << '\n'; | |
return 0; | |
} |
우선순위 큐
맨 처음에 그냥 sort 사용해서 풀었는데, 메모리 초과 오류가 나서 우선순위큐 이용해서 품
'코테준비 > 백준' 카테고리의 다른 글
백준 [10026] 적록색약 (0) | 2022.10.12 |
---|---|
백준 [2606] 바이러스 (0) | 2022.10.11 |
백준 [1339] 단어 수학 (0) | 2022.09.05 |
백준 [1931] 회의실 배정 (0) | 2022.09.05 |
백준 [13164] 행복 유치원 (0) | 2022.09.02 |