In a university, the student council has introduced a new voting system to decide on various proposals. Each student can cast a vote with a specific numeric value representing the priority they place on a proposal. The council needs a system to manage these votes efficiently.
Your goal is to help the student council by developing a program that manages the voting numbers. The system should be able to add votes, remove votes, and quickly determine the highest priority vote still active.
Operations:
x
to the system. If x
is already present, it will be added again.x
from the system. If x
is not present, no action is taken.Hint
How to get the minimum value in the std::multiset
or std::set
std::multiset<int> st = {1, 2, 3}; auto it = st.begin(); std::cout << "minimum = " << *it;
How about get the maximum value in the std::multiset
or std::set
std::multiset<int> st = {1, 2, 3}; auto it = prev(st.end()); std::cout << "maximum = " << *it;
set::end()
returns an iterator pointing to the next element of the last one in the container (Like a dummy node in linked-list). Since it does not refer to a valid element, it cannot use '*' to dereferenced end() function.
std::next()
& std::prev()
are useful function to move through iterators.
When using multiset, please notice the following difference of multiset::erase()
.
std::multiset<int> st = {1, 1, 1}; st.erase(1); // delete all three "1" st.erase(st.find(1)); // delete one "1"
Remember: if the set is empty or the iterator you are using point to a invalid element, using '*', 'std::next()', 'set:erase()' or other function might lead to Runtime Error.
Q
, the number of operations.Q
lines describe the operations. "Add" and "Remove" operation are formatted as a string followed by an integer x
.Constraints: