백준 21939 문제 추천 시스템 Version 1

supway·2022년 2월 26일
0

백준

목록 보기
37/62

백준 21939

#include <bits/stdc++.h>
#include<set>
#include<map>
using namespace std;
int n,m;
int main() {
	ios::sync_with_stdio(0); cin.tie(0);

	multiset<pair<int,int>> s;
	map<int,int> mp;

	cin >> n;

	while (n--) {
		int a, b;
		cin >> a >> b;
		s.insert({ b,a });
		mp[a] = b;
	}

	cin >> m;

	while (m--) {
		string s1;
		cin >> s1;

		int a, b;
		if (s1 == "add") {
			cin >> a >> b;
			mp[a] = b;
			s.insert({ b,a });
		}
		else {
			cin >> a;
			if (s1 == "recommend") {
				if (a == 1) {
					cout << (*--s.end()).second << '\n';
				}
				else {
					cout << (*s.begin()).second << '\n';
				}
			}
			else if (s1 == "solved") {
				s.erase({ mp[a],a });
			}
		}

	}
}
profile
개발잘하고싶은사람

0개의 댓글