ABC471D题解
首先我们容易想到暴力线段树维护最大值的做法,但码量很大。考虑有没有更好写的代码。
注意到一个在 multiset 或优先队列维护
时间复杂度为
代码如下:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5;
int n,op,t,w,v;
multiset<int,greater<int> >s;
void solve()
{
cin>>n>>v;
for(int i=1;i<=n;i++)
{
cin>>op>>t;
if(op==1) cin>>w,s.insert(w-t);
else
{
if(s.empty()) cout<<"-1\n";
else cout<<min(v,*(s.begin())+t)<<'\n',s.erase(s.begin());
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int _=1;//cin>>_;
while(_--) solve();
return 0;
}