Submission #721128

#TimeUsernameProblemLanguageResultExecution timeMemory
721128lamAnts and Sugar (JOI22_sugar)C++14
6 / 100
4054 ms2640 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...