#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
//Don't open the standings during contests.
const int mxn=1e6+5;
vector<int>a(mxn),s(mxn),p(mxn),b(mxn),t(mxn),q(mxn);
int pre[mxn],pre2[mxn];
vector<pii>pt[mxn];
int dif[mxn];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i]>>s[i]>>p[i];
pre[i]=pre[i-1]+a[i];
}
for(int i=1;i<=m;i++){
cin>>b[i]>>t[i]>>q[i];
pre2[i]=pre2[i-1]+b[i];
}
int ans=0;
for(int i=1;i<=n;i++){
int x=upper_bound(pre2+1,pre2+m+1,s[i]-pre[i])-pre2;
ans+=p[i];
if(x<=m)pt[i].pb({x,-p[i]});
}
for(int j=1;j<=m;j++){
int y=upper_bound(pre+1,pre+n+1,t[j]-pre2[j])-pre;
pt[y].pb({j,q[j]});
}
set<int>st;
for(int i=0;i<=n;i++){
sort(all(pt[i]));
for(auto [x,y]:pt[i]){
if(st.find(x)==st.end()){
st.insert(x);
dif[x]=0;
}
dif[x]+=y;
}
for(auto [x,fuck]:pt[i]){
//維護前綴max所以把dif<0的都刪掉
auto it=st.find(x);
while(it!=st.end() and dif[*it]<0){
int temp=dif[*it];
it=st.erase(it);
if(it!=st.end())dif[*it]+=temp;
}
}
}
for(auto i:st)ans+=dif[i];
cout<<ans<<'\n';
}
/*
input:
2 3 6
2 1 3
2 2 2
*/
Compilation message
dishes.cpp: In function 'int main()':
dishes.cpp:47:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
47 | for(auto [x,y]:pt[i]){
| ^
dishes.cpp:54:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
54 | for(auto [x,fuck]:pt[i]){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
210 ms |
111976 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
74072 KB |
Output is correct |
2 |
Incorrect |
14 ms |
74076 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
74072 KB |
Output is correct |
2 |
Incorrect |
14 ms |
74076 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
74072 KB |
Output is correct |
2 |
Incorrect |
14 ms |
74076 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
74072 KB |
Output is correct |
2 |
Incorrect |
14 ms |
74076 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
74072 KB |
Output is correct |
2 |
Incorrect |
14 ms |
74076 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
210 ms |
111976 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
210 ms |
111976 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |