#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define fopen freopen("input.txt", "r", stdin)
#define eb emplace_back
#define em emplace
#define prec(a) cout<<fixed;cout.precision(a);
#define all(a) (a).begin(), (a).end()
typedef long long ll;typedef long double ld;typedef unsigned long long ul;typedef unsigned int ui;typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tiii;
const ll INF = 2e18;
const int inf = 2e9;
template<class T>
void pr(T t) {cerr << t << " ";}
template<class T, class ...Args>
void pr(T a, Args ...args) {cerr << a << " ";pr(args...);}
template<class ...Args>
void prl(Args ...args) {pr(args...);cerr << endl;}
int n, m;
struct In{
ll ti, lim, cost;
}A[1000100], B[1000100];
ll ans;
vector<pll> ad[1000100];
ll asum[1000100],bsum[1000100];
ll seg[3000100];
bool flag[3000100];
void prop(int x, int l, int r){
if(!flag[x]) return ;
if(l!=r){
flag[x*2]=flag[x*2+1]=true;
seg[x*2]=seg[x*2+1]=0;
}
seg[x] = flag[x] = 0;
return ;
}
ll get(int x, int l, int r, int s, int e){
prop(x, l, r);
if(r<s||e<l||s>e) return 0;
if(s<=l&&r<=e) return seg[x];
return get(x*2, l, (l+r)/2, s, e)+get(x*2+1, (l+r)/2+1,r,s,e);
}
void clr(int x, int l, int r, int s, int e){
prop(x, l, r);
if(r<s||e<l||s>e) return ;
if(s<=l&&r<=e){
flag[x]=true;
prop(x,l,r);
return ;
}
clr(x*2, l, (l+r)/2, s, e);clr(x*2+1, (l+r)/2+1,r,s,e);
seg[x]=seg[x*2]+seg[x*2+1];
}
void add(int x, int l, int r, int i, ll v){
prop(x,l,r);
if(r<i||i<l) return ;
if(l==r){
seg[x]+=v;return ;
}
int m = (l+r)/2;
if(i<=m) add(x*2, l, m, i, v);
else add(x*2+1, m+1,r,i,v);
seg[x] = seg[x*2]+seg[x*2+1];
}
int get_left(int x, int l, int r, ll v){
prop(x,l,r);
if(l==r) return l;
if(seg[x*2]>v) return get_left(x*2, l,(l+r)/2, v);
return get_left(x*2+1, (l+r)/2+1, r, v-seg[x*2]);
}
int main(){
fastio;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>A[i].ti>>A[i].lim>>A[i].cost;
asum[i]=asum[i-1]+A[i].ti;
}
for(int i=1;i<=m;i++){
cin>>B[i].ti>>B[i].lim>>B[i].cost;
bsum[i]=bsum[i-1]+B[i].ti;
}
for(int i=1;i<=n;i++){
if(asum[i]>A[i].lim) continue;
int j = upper_bound(bsum,bsum+m+1, A[i].lim-asum[i])-bsum-1;
ans+=A[i].cost;
ad[i-1].eb(j+1, -A[i].cost);
}
for(int i=1;i<=m;i++){
if(bsum[i]>B[i].lim) continue;
int j = upper_bound(asum,asum+n+1, B[i].lim-bsum[i])-asum-1;
ad[j].eb(i,B[i].cost);
}
for(int i=0;i<=n;i++){
sort(all(ad[i]), [](pll &a,pll &b){
if(a.fi==b.fi) a.se>b.se;
return a.fi>b.fi;
});
for(auto j:ad[i]){
if(j.se>=0){
add(1,0,m,j.fi,j.se);
continue;
}
else{
ll t = get(1,0,m,0,j.fi-1);
if(get(1,0,m,0,m)<=t-j.se){
clr(1,0,m,j.fi,m);
continue;
}
int ind = get_left(1,0,m,t-j.se);
ll v = get(1,0,m,0,ind)-get(1,0,m,ind,ind)-t+j.se;
if(j.fi<=ind-1) clr(1,0,m,j.fi,ind-1);
add(1,0,m,ind,v);
}
}
}
cout<<ans+get(1,0,m,0,m);
}
Compilation message
dishes.cpp: In lambda function:
dishes.cpp:101:23: warning: statement has no effect [-Wunused-value]
if(a.fi==b.fi) a.se>b.se;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
421 ms |
54008 KB |
Output is correct |
2 |
Incorrect |
381 ms |
54772 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
23808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
23808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
23808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
23808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
23808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
421 ms |
54008 KB |
Output is correct |
2 |
Incorrect |
381 ms |
54772 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
421 ms |
54008 KB |
Output is correct |
2 |
Incorrect |
381 ms |
54772 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |