Submission #548955

#TimeUsernameProblemLanguageResultExecution timeMemory
548955inksamuraiAnts and Sugar (JOI22_sugar)C++17
6 / 100
268 ms784 KiB
#include <bits/stdc++.h>
#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,x,n) for(int i=x;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3rfKJyA ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e

signed main(){
_3rfKJyA;
	int q,lan;
	cin>>q>>lan;
	assert(q<=5000);
	vec(pii) a,b,na,nb;
	rep(_,q){
		int t,x,c;
		cin>>t>>x>>c;
		if(t==1){
			na.pb({x,c});
		}else{
			nb.pb({x,c});
		}
		a=na,b=nb;
		sort(a.begin(),a.end());
		sort(b.begin(),b.end());
		int res=0,j=0;
		for(int i=0;i<sz(a);i++){
			if(j==sz(b) or b[j].fi-a[i].fi>lan){
				continue;
			}
			while(j<sz(b) and a[i].fi-b[j].fi>lan){
				j=j+1;
			}
			while(j<sz(b) and abs(a[i].fi-b[j].fi)<=lan and a[i].se){
				int tk=min(a[i].se,b[j].se);
				res+=tk;
				a[i].se-=tk;
				b[j].se-=tk;
				if(b[j].se==0){
					j=j+1;
				}
			}
		}
		print(res);
	}
//	
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...