-
(이진 검색 트리)7662 이중 우선순위 큐Algorithm/baekjoon 2022. 2. 25. 15:32
https://www.acmicpc.net/problem/7662
7662번: 이중 우선순위 큐
입력 데이터는 표준입력을 사용한다. 입력은 T개의 테스트 데이터로 구성된다. 입력의 첫 번째 줄에는 입력 데이터의 수를 나타내는 정수 T가 주어진다. 각 테스트 데이터의 첫째 줄에는 Q에 적
www.acmicpc.net
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<string> #include<vector> #include<algorithm> #include<queue> #include<set> using namespace std; multiset<int> ms; int main() { cin.tie(NULL); cin.sync_with_stdio(false); cout.tie(NULL); int T; cin >> T; while (T--) { int k; cin >> k; while (k--) { char doing = 'A'; cin >> doing; if (doing == 'D') { int num; cin >> num; if (ms.empty()) continue; if (num == 1) ms.erase(prev(ms.end())); else ms.erase(ms.begin()); } else { int num; cin >> num; ms.insert(num); } } if (ms.empty())cout << "EMPTY\n"; else { cout << *prev(ms.end()) << " " << *ms.begin() << "\n"; } ms.clear(); } return 0; }
'Algorithm > baekjoon' 카테고리의 다른 글
(dp)1463 1로 만들기/9095 1,2,3 더하기 (0) 2022.02.22 (bfs/dfs)4963 섬의 개수 (0) 2022.02.22 1260 DFS와 BFS/11724 연결요소의 개수 (0) 2022.02.20 (재귀)1629 곱셈/1074 Z (0) 2022.02.19 1978 소수 찾기/2609 최대공약수와 최소공배수 (0) 2022.02.19