접근 방법
우선순위 큐에 N만큼의 크기를 유지시키면서 pq의 최솟값을 갱신시켜주면 결과적으로 전체 세트의 N번째 최댓값을 쉽게 구할 수 있다.
Priority queue 사용 느낌에 대해서 다시 한번 정리하는 용도로 정리해주면 된다.
코드
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
int main(void){
fastio;
int n;
cin >> n;
priority_queue<int, vector<int>, greater<int> > pq;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
int temp;
cin >> temp;
if(pq.size() < n) pq.push(temp);
else{
if(pq.top() < temp){
pq.pop();
pq.push(temp);
}
}
}
}
cout << pq.top() << "\n";
return 0;
}
난이도 평가 칸에 들어가면 메모리 부족때문에 안될 줄 알았는데
단순 sort로도 풀린다는 말이 있다..