This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> ii;
#define ff first
#define ss second
const int maxn = 5e5 + 10;
int n,L;
multiset<ii> ms[2];
int query()
{
multiset<ii> nms[2];
nms[0]=ms[0]; nms[1]=ms[1];
int ans=0;
for (ii i:nms[0])
{
while (!nms[1].empty()&&nms[1].begin()->ff + L < i.ff) nms[1].erase(nms[1].begin());
while (i.ss>0&&!nms[1].empty()&&abs(i.ff-nms[1].begin()->ff) <= L)
{
auto it = nms[1].begin();
ii temp = *it;
int val = min(i.ss,temp.ss);
nms[1].erase(it);
ans+=val;
temp.ss-=val;
i.ss-=val;
if (temp.ss > 0) nms[1].insert(temp);
}
}
return ans;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin>>n>>L;
for (int i=0; i<n; i++)
{
int t; cin>>t;
if (t==1)
{
int x,y; cin>>x>>y;
ms[0].insert({x,y});
}
else
{
int x,y; cin>>x>>y;
ms[1].insert({x,y});
}
cout<<query()<<'\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |