1008_《阿里巴巴集团杯》ACM华工赛点网络赛最后一题

 

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

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.

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掉,如果不一样则输出,再把它放入垃圾桶。
代码如下:

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值