Submission #1070242

#TimeUsernameProblemLanguageResultExecution timeMemory
1070242Ahmed57Two Dishes (JOI19_dishes)C++17
74 / 100
2709 ms196112 KiB
#include "bits/stdc++.h" using namespace std; #define int long long vector<pair<int,int>> lol[1000001]; int arr1[1000001] = {0}; int arr2[1000001] = {0}; int a[1000001];int s[1000001];int p[1000001]; int b[1000001];int t[1000001];int q[1000001]; signed main(){ int n,m; cin>>n>>m; for(int i = 1;i<=n;i++){ cin>>a[i]>>s[i]>>p[i]; arr1[i] = a[i]+arr1[i-1]; } for(int i = 1;i<=m;i++){ cin>>b[i]>>t[i]>>q[i]; arr2[i] = b[i]+arr2[i-1]; } for(int i = 1;i<=n;i++){ int l = 0 , r = m , ans = -1; while(l<=r){ int mid = (l+r)/2; if(arr2[mid]+arr1[i]<=s[i]){ ans = mid;l = mid+1; }else r = mid-1; } if(ans==-1)continue; lol[ans].push_back({i,p[i]}); } long long all = 0; for(int i = 1;i<=m;i++){ int l = 0 , r = n , ans = -1; while(l<=r){ int mid = (l+r)/2; if(arr2[i]+arr1[mid]<=t[i]){ ans = mid;l = mid+1; }else r = mid-1; } if(ans==-1)continue; lol[i-1].push_back({ans+1,-q[i]}); all+=q[i]; } map<int,int> mp; for(int i = 0;i<=m;i++){ for(auto j:lol[i]){ if(j.second>=0){ mp[j.first]+=j.second; continue; } int ans = j.second; auto it = mp.lower_bound(j.first); while(it!=mp.end()){ if(ans+(*it).second>=0){ mp[(*it).first]+=ans; ans = 0; break; } ans+=(*it).second; it = mp.erase(it); } } } for(auto i:mp)all+=i.second; cout<<all<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...