728x90
programmers.co.kr/learn/courses/30/lessons/42628
#include <string>
#include <vector>
#include <queue>
#include<sstream>
using namespace std;
vector<int> solution(vector<string> operations) {
vector<int> answer;
priority_queue<int>q;
string s[2];
int minimum =0;
for(int i=0; i<operations.size(); i++){
stringstream ss(operations[i]);
ss>>s[0]>>s[1];
if(s[0]=="I"){q.push(stoi(s[1]));}
else{
if(s[1]=="1"&& q.size()>0){q.pop();}
else if(s[1]=="-1"&&q.size()>0){minimum++;}
}
}
if(q.size()<=minimum){answer.push_back(0); answer.push_back(0);}
else{
int popsz = q.size()-minimum;
int mx = q.top();
for(int i=0; i<popsz-1; i++){q.pop();}
int mn = q.top();
answer.push_back(mx); answer.push_back(mn);
}
return answer;
}