Problem H
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 605 Accepted Submission(s) : 84
Problem Description
CC is an apple fans. His house is around apple tree. He likes picks the apple and take back to home. And He may eat the best apple or throws the worse apple.
Input
the First line contain a Integer N (0<=N<=1000000)
the follow N lines, every line begin a word.
the word can be pick, eat or throw
if the word is “pick”, an Integer A (0<A<2^31)would follow means this apple's score is A
if the word is “eat”, means he eats the apple
if the word is “throw”, means he throws the apple
the follow N lines, every line begin a word.
the word can be pick, eat or throw
if the word is “pick”, an Integer A (0<A<2^31)would follow means this apple's score is A
if the word is “eat”, means he eats the apple
if the word is “throw”, means he throws the apple
Output
when you get the word “eat”, you should output the best score in CC's home or -1 if there is no apple at home
when you get the word “throw”, you should output the worse score in CC's home -1 if there is no apple at home
every answer should be print in a line.
when you get the word “throw”, you should output the worse score in CC's home -1 if there is no apple at home
every answer should be print in a line.
Sample Input
9 eat pick 1 pick 2 pick 3 pick 4 pick 5 eat throw eat
Sample Output
-1 5 1 4
好像有人用最大最小堆做的,那个我不懂,我只是用四个priority_queue做:两个保存最大和最小(max_pq, min_pq),另外两个
作为垃圾桶(tmp_maxpq, tmp_minpq),即把要删除的元素放入垃圾桶,等到下一次要取最大值(或最小值)时,在最大值(或最小
值)的垃圾桶里看top元素是不是一样,如果一样则都一起pop掉,如果不一样则输出,再把它放入垃圾桶。
代码如下: