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();
}
}
}