Maintain a dynamic set of members whose top floor(20%) by motivation and join time are workhorses, and log every time a member's status flips after each join or departure.
Medium7TreeSortingImplementationBinary searchInterviewNo attempts yetTime limit2sMemory limit512 MBACM is an organization that holds programming contests. What ACM is for does not matter to you. The only thing that matters is that the work styles of its members are polarized: each member is either a workhorse or an idle fellow.
Each member of ACM has a motivation level. The members are ranked by motivation level. A member with a higher motivation level is ranked higher, and when several members have the same motivation level, the member who joined ACM later is ranked higher. The top 20% of the ranking work hard, and the other 80% never (!) work. If 20% of the number of members is not an integer, the fractional part is rounded down.
You, a manager of ACM, wanted to know whether each member is a workhorse or an idle fellow so that you can manage ACM. You have finally finished evaluating the motivation levels of all current members. Your task is not done yet, though, because the membership of ACM changes from day to day as members join and leave. So you want to record every moment when a member changes from a workhorse to an idle fellow, or the other way around.
You are given the list of the current members of ACM and their motivation levels, in chronological order of the date each member joined. You are also given the list of joins and departures in chronological order.
Write a program that computes every change of work style among the members of ACM.
The first line contains a single integer N (1 ≤ N ≤ 50,000), the number of initial members of ACM. The i-th of the next N lines contains a string si and an integer ai (0 ≤ ai ≤ 105), separated by a single space. si is the name of the i-th initial member and ai is that member's motivation level. Each character of si is an English letter, and 1 ≤ ∣si∣ ≤ 20. These N lines are sorted in chronological order of the date each member joined ACM.
Line N + 2 contains a single integer M (1 ≤ M ≤ 20,000), the number of membership changes. The j-th of the next M lines describes the j-th join or departure. When the j-th event is a join, the line has the form "+ tj bj", where tj is the name of the joining member and bj (0 ≤ bj ≤ 105) is that member's motivation level. When the j-th event is a departure, the line has the form "- tj", where tj is the name of the departing member. Each character of tj is an English letter, and 1 ≤ ∣tj∣ ≤ 20. Uppercase and lowercase letters are distinct. These M lines are sorted in chronological order of the date each event happened.
No two join or departure events happen at the same time. No two members have the same name at the same time, but a member who left ACM once may join ACM again.
Print the log, a sequence of changes in chronological order. Whenever one of the following two changes happens, print the message for that change on its own line.
For each join or departure, the changes happen in the following order.
First test case: initially nobody works because 4 × 20% < 1. When one member joins ACM, Durett begins to work hard.
Second test case: nobody works.
Fourth test case: a member may join and leave repeatedly.