Creative Code

[7662번]이중 우선순위 큐 본문

백준 문제풀이

[7662번]이중 우선순위 큐

빛하루 2023. 9. 24. 17:37

https://www.acmicpc.net/problem/7662

 

7662번: 이중 우선순위 큐

입력 데이터는 표준입력을 사용한다. 입력은 T개의 테스트 데이터로 구성된다. 입력의 첫 번째 줄에는 입력 데이터의 수를 나타내는 정수 T가 주어진다. 각 테스트 데이터의 첫째 줄에는 Q에 적

www.acmicpc.net

#include <iostream>
#include <set>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int t, k, n;
	char c;

	cin >> t;
	for (int i = 0; i < t; i++) {
		cin >> k;
		multiset<int> m;

		for (int j = 0; j < k; j++) {
			cin >> c >> n;
			if (c == 'I') {
				m.insert(n);
			}
			else {
				if (!m.empty() && n == -1) {
					m.erase(m.begin());
				}
				else if (!m.empty() && n == 1) {
					auto iter = m.end();
					iter--;
					m.erase(iter);
				}
			}
		}
		if (m.empty()) {
			cout << "EMPTY" << "\n";
		}
		else {
			auto it = m.end();
			it--;
			cout << *it << " " << *m.begin() << "\n";
		}
	}
	return 0;
}

'백준 문제풀이' 카테고리의 다른 글

[9663번]N-Queen  (0) 2023.09.24
[9019번]DSLR  (0) 2023.09.24
[1806번]부분합  (0) 2023.09.24
[1753번]최단경로  (0) 2023.09.24
[1043번]거짓말  (0) 2023.09.24