Skip to content
Snippets Groups Projects
Commit 4a26326e authored by 김시환's avatar 김시환
Browse files

22.01.24

parent 95ac6524
Branches master
No related tags found
No related merge requests found
#include<iostream>
#include<queue>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N;
cin >> N;
priority_queue<int, vector<int>, greater<int>> plus;
priority_queue<int, vector<int>, less<int>> minus;
for(int i=0;i<N;i++)
{
int x;
cin >> x;
if(x == 0)
{
if(plus.empty() && minus.empty())
{
cout << 0 << "\n";
}
else if(plus.empty() && !minus.empty())
{
cout << minus.top() << "\n";
minus.pop();
}
else if(!plus.empty() && minus.empty())
{
cout << plus.top() << "\n";
plus.pop();
}
else
{
int p_top = plus.top();
int m_top = minus.top();
if(p_top == -1 * m_top)
{
cout << m_top << "\n";
minus.pop();
}
else if(p_top > -1 * m_top)
{
cout << m_top << "\n";
minus.pop();
}
else
{
cout << p_top << "\n";
plus.pop();
}
}
}
else if(x > 0)
{
plus.push(x);
}
else
{
minus.push(x);
}
}
}
\ No newline at end of file
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int cnt=0;
map<string, int> m;
string input;
while(getline(cin, input))
{
m[input]++;
cnt++;
}
cout << fixed;
cout.precision(4);
for(auto i:m)
{
cout << i.first << " " << (double) i.second * 100 / cnt << endl;
}
}
\ No newline at end of file
#include<iostream>
#include<vector>
#include<queue>
#include<map>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin >> T;
while(T--)
{
map<int, int> m;
priority_queue<int, vector<int>, greater<int>> min_heap;
priority_queue<int, vector<int>, less<int>> max_heap;
int K;
cin >> K;
while(K--)
{
int n;
char op;
cin >> op >> n;
if(op =='D')
{
if(n == 1)
{
while(!max_heap.empty() && m[max_heap.top()] == 0)
max_heap.pop();
if(max_heap.empty())
continue;
else
{
m[max_heap.top()]--;
max_heap.pop();
}
}
else
{
while(!min_heap.empty() && m[min_heap.top()] == 0)
min_heap.pop();
if(min_heap.empty())
continue;
else
{
m[min_heap.top()]--;
min_heap.pop();
}
}
}
else
{
max_heap.push(n);
min_heap.push(n);
m[n]++;
}
while(!max_heap.empty() && m[max_heap.top()] == 0)
max_heap.pop();
while(!min_heap.empty() && m[min_heap.top()] == 0)
min_heap.pop();
}
if(max_heap.empty())
cout << "EMPTY\n";
else
cout << max_heap.top() << " " << min_heap.top() << "\n";
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment