-
Notifications
You must be signed in to change notification settings - Fork 0
/
7662.cpp
127 lines (110 loc) · 2.15 KB
/
7662.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* [Author]
* Byeong Heon Lee
* lww7438@gmail.com
* https://dad-rock.tistory.com/927 (Korean)
*
*/
// Problem URL
// https://www.acmicpc.net/problem/7662
// Debug Switch
// #define DEBUG_MODE
// Header Files
#include <iostream>
#include <set>
// Namespace & Aliases
using namespace std;
typedef int INT;
// Constants
const int MAX = 1000;
// Global Variables
multiset<int> heap; // Priority queue (Heap)
int T; // # of test cases
int k; // # of operations for priority queue
char op_code; // Operation code
int n; // Item for operation
// Function Prototypes
void get_input();
void run();
void set_output();
void deallocate();
int main();
/*
* Function Name : get_input
* Parameters : -
* Return Type : -
* Description : Getting data and store it in the appropriate data structures
*/
void get_input()
{
// C++ Fast I/O Mechanism
// https://dad-rock.tistory.com/737 (Korean)
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> op_code >> n;
}
/*
* Function Name : run
* Parameters : -
* Return Type : -
* Description : Main Logic
*/
void run()
{
if (op_code == 'I')
heap.insert(n);
else if (op_code == 'D')
{
if (heap.empty())
return;
if (n == -1)
heap.erase(heap.begin());
else if (n == 1)
heap.erase(--heap.end());
}
}
/*
* Function Name : set_output
* Parameters : -
* Return Type : -
* Description : Setting the output
*/
void set_output()
{
if (heap.empty())
cout << "EMPTY\n";
else
cout << *(--heap.end()) << ' ' << *(heap.begin()) << '\n';
}
/*
* Function Name : deallocate
* Parameters : -
* Return Type : -
* Description : Deallocate the heap
*/
void deallocate()
{
heap.clear();
}
/*
* Function Name : main
* Parameters : -
* Return Type : -
* Description : Main Function
*/
int main()
{
cin >> T;
while (T--)
{
cin >> k;
while (k--)
{
get_input();
run();
}
set_output();
deallocate();
}
return EXIT_SUCCESS;
}