백준 문제풀이

백준 7662번 - C++

diligent_gideok 2022. 5. 26. 19:49
#include <bits/stdc++.h>
using namespace std;

int t,n;


int main(void) {
	ios::sync_with_stdio(0);
	cin.tie();
	cin >> t;

	while (t--) {
		multiset<int> ms;
		int k;
		cin >> k;
		while (k--) {
			char c;
			cin >> c>>n;
			if (c == 'I') {
				ms.insert(n);
			}
			else { // c=='D'
				if (ms.empty()) continue;
				if (n == 1) {
					auto it1 = prev(ms.end());
					ms.erase(it1);
				}
				else { // n==-1
					auto it1 = ms.begin();
					ms.erase(it1);
				}
			}
		}
		if (ms.empty()) cout << "EMPTY\n";
		else cout << *prev(ms.end()) << ' ' << *ms.begin() << '\n';

	}
}

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

백준 21939번 - C++  (0) 2022.05.26
백준 1202번 - C++  (0) 2022.05.26
백준 7785번 - C++  (0) 2022.05.22
백준 1292번 - C++  (0) 2022.05.19
백준 1806번 - C++  (0) 2022.05.18