典型的优先队列题。如果每次都排序的话绝对T。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define pb push_back
#define fi first
#define se second
#define mem(a,x) memset(a,x,sizeof(a));
#define db double
#define fir(i,a,n) for(int i=a;i<=n;i++)
//======================
const int N=2e5+10;
int x;ll y;ll ans,add;
priority_queue<ll,vector<ll>,greater<ll>>pq;//从小到大
int main()
{
int t;scanf("%d",&t);
while(t--)
{
scanf("%d",&x);
if(x==1||x==2) scanf("%d",&y);
if(x==1) pq.push(y-add);
else if(x==2) add+=y;
else
{
ans=pq.top();
pq.pop();
cout<<1ll*(ans+add)<<endl;
}
}
return 0;
}