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>
using namespace std;
#define int long long
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
//freopen("input.txt","r",stdin);
//freopen("outout.txt","w",stdout);
int n,m;
cin>>n>>m;
multiset<array<int,3>> s;
for(int i = 1;i<=n;i++){
int t,x,a;
cin>>t>>x>>a;
s.insert({x,t,a});multiset<pair<int,int>> sugar,ants;
long long all = 0;
for(auto i:s){
int rem = i[2];
if(i[1]==2){
while(!ants.empty()&&abs((-(*ants.begin()).first)-i[2])<=m&&rem){
int pos = (*ants.begin()).first;
int sec = (*ants.begin()).second;
int e = min(sec,rem);
rem-=e;sec-=e;
all+=e;
if(sec!=0){
ants.insert({pos,sec});
}
}
if(rem)sugar.insert({-i[0],rem});
}else{
while(!sugar.empty()&&abs((-(*sugar.begin()).first)-i[2])<=m&&rem){
int pos = (*sugar.begin()).first;
int sec = (*sugar.begin()).second;
int e = min(sec,rem);
rem-=e;sec-=e;
all+=e;
if(sec!=0){
sugar.insert({pos,sec});
}
}
if(rem)ants.insert({-i[0],rem});
}
}
cout<<all<<endl;
}
}
# | 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... |