14298 - Student Council Election System   

Description

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:

  1. Add x: Adds a vote with value x to the system. If x is already present, it will be added again.
  2. Remove x: Removes one instance of the vote with value x from the system. If x is not present, no action is taken.
  3. Max: Returns the highest vote value currently in the system. If no votes are present, print "No votes recorded".
  4. Min:  Returns the lowest vote value currently in the system. If no votes are present, print "No votes recorded".

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.

Input

  • The first line contains an integer Q, the number of operations.
  • The next Q lines describe the operations. "Add" and "Remove" operation are formatted as a string followed by an integer x.

Constraints:

  • 1 ≤ Q ≤ 200000
  • −10≤ x ≤ 109

Output

  • For each "Max" and "Min" operation, output the result in a new line.
  • If no votes are present, print "No votes recorded".

Sample Input  Download

Sample Output  Download

Tags




Discuss