取球游戏。

Background

Special for beginners, ^_^

Description

小J有很多空白的球和一个袋子。最初,袋子是空的。

小J将会作出Q个操作,具体如下:

操作1 在白球上写一个数字Xi然后扔进袋子里;

操作2 将袋子里所有球的数字都加上Xi;

操作3 输出袋子里最小的数字并把它从袋子里取出。

Q<=2*100000

xi<=1e9

Format

Input

输入Q个操作 ,接下来的Q行,每行一个操作,可以是操作1,操作2或操作3,具体格式如 1 5 ,表示操作1 在白球上写一个数字5然后扔进袋子里;

Output

针对每个操作3,输出结果。

Samples

输入数据 1

5
1 3
1 5
3
2 2
3

Copy

输出数据 1

3
7

Copy

Limitation

1s, 256024KiB for each test case.

这题不能读到2就增加数,会超时,所以用一个s来记录增加的值,进来的就减s,输出时就加s,这样数据就没问题了

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<iomanip>
#include<set>
#include<queue>
#include<stack> 
#include<map>
using namespace std;
long long q,f,s = 0;//询问次数,操作类型,s为增加的数值
priority_queue<int, vector<int>, greater<int>>qq;//优先队列存球
int main()
{
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		cin >> f;
		if (f == 1)//球入袋
		{
			int a1;
			cin >> a1;
			qq.push(a1 - s);
		}
		if (f == 2)
		{
			int a2;
			cin >> a2;
			s = s + a2;
		}
		if (f == 3)
		{
			cout << qq.top() + s << endl;
			qq.pop();
		}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值