Question: n operations
Push into container
Pop pops up a maximum value <= this value (if No Element is output !)
I started to use set to repeat wrong. Here, the number of input containers is repeated, so the multiset
# Include <stdio. h ># include <set> using namespace std; multiset <int> ss; multiset <int >:: iterator p, q; int main () {int n, t; char c [5]; while (~ Scanf ("% d", & n) {ss. clear (); while (n --) {scanf ("% s % d", c, & t); if (c [1] = 'U') ss. insert (t); else {if (ss. size () = 0 | * ss. begin ()> t) {printf ("No Element! \ N "); continue;} ss. insert (t); q = ss. find (t); // returns the first iteration equal to t p = q; p ++; if (p! = Ss. end () & * p = t) t = * p; else {p --; t = * p;} printf ("% d \ n ", t); ss. erase (p); ss. erase (q) ;}} printf ("\ n");} return 0 ;}/ * 7 Push 2 Push 5Pop 2Pop 3Pop 4Pop 5Pop 6 */