Submission #545682

#TimeUsernameProblemLanguageResultExecution timeMemory
545682leakedAnts and Sugar (JOI22_sugar)C++14
6 / 100
4064 ms2072 KiB
#include <bits/stdc++.h> #define f first #define s second #define m_p make_pair #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define vec vector #define pb push_back #define sz(x) (int)(x).size() #define pw(x) (1LL<<(x)) #define fast_prep ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef long double ld; typedef pair<int,ll> pil; template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);} template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);} signed main(){ fast_prep; int n,k; cin>>n>>k; map<int,ll> x,y; auto solve=[&](){ ll ans=0; map<int,ll> mp=y; map<int,ll> mpt=x; for(auto &z : mpt){ while(z.s){ auto it=mp.lower_bound(z.f-k); if(it==mp.end() || abs(it->f-z.f)>k) break; int j=it->f; ll mn=min(mp[j],z.s); ans+=mn; z.s-=mn;mp[j]-=mn; if(!mp[j]) mp.erase(j); } } return ans; }; for(int i=0;i<n;i++){ int t; cin>>t; if(t==2){ int i,vl; cin>>i>>vl; x[i]+=vl; } else{ int i,vl; cin>>i>>vl; y[i]+=vl; } cout<<solve()<<'\n'; } 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...