#include <bits/stdc++.h>
using namespace std;
/*
struct seg {
	vector<int> val, lazy;
	int n, h;
	seg(int _n): n(_n), h(32-__builtin_clz(_n)), val(2*_n,0), lazy(_n,0) {}
	void app(int x, int k) {
		val[x] += k;
		if(x < n)
			lazy[x] += k;
	}
	void calc(int x) {
		val[x] = max(val[x<<1],val[x<<1|1]) + lazy[x];
	}
	void push(int x) {
		for(int i=h;i;i--) {
			int y = (x >> i);
			app(y<<1,lazy[y]);
			app(y<<1|1,lazy[y]);
			lazy[y] = 0;
		}
	}
	void build(int x) {
		while(x>>1)
			calc(x);
	}
	void up(int l, int r, int x) {
		int l0 = l+=n;
		int r0 = r+=n;
		push(l0);
		push(r0);
		for(r++;l<r;l>>=1,r>>=1) {
			if(l&1)
				app(l++,x);
			if(r&1)
				app(--r,x);
		}
		build(l0);
		build(r0);
	}
	int qry(int l, int r) {
		push(l+=n);
		push(r+=n);
		int ans = 0;
		for(r++;l<r;l>>=1,r>>=1) {
			if(l&1)
				ans+=val[l++];
			if(r&1)
				ans+=val[--r];
		}
		return ans;
	}
};
*/
struct seg {
	vector<int> val;
	seg(int _n): val(_n,0) {}
	void up(int l, int r, int x) {
		for(int i=l;i<=r;i++)
			val[i]+=x;
	}
	int qry(int l, int r) {
		int ans=0;
		for(int i=l;i<=r;i++)
			ans=max(ans,val[i]);
		return ans;
	}
};
int main() {
	int n, m;
	cin >> n >> m;
	long long a[n], s[n], b[m], t[m];
	for(int i=0,trash;i<n;i++)
		cin >> a[i] >> s[i] >> trash;
	for(int i=0,trash;i<m;i++)
		cin >> b[i] >> t[i] >> trash;
	long long pa[n+1], pb[m+1];
	pa[0] = pb[0] = 0;
	partial_sum(a,a+n,pa+1);
	partial_sum(b,b+m,pb+1);
	long long ans = 0;
	for(int i=0;i<n;i++) {
		s[i] = upper_bound(pb,pb+m+1,s[i]-pa[i+1])-pb-1;
		if(s[i] == m) {
			s[i] = -1;
			ans++;
		}
	}
	vector<int> edge[n];
	for(int i=0;i<m;i++) {
		t[i] = upper_bound(pa,pa+n+1,t[i]-pb[i+1])-pa-1;
		if(t[i] == n) {
			t[i] = -1;
			ans++;
		} else
			edge[t[i]].push_back(i);
	}
	seg dp(m+1);
	for(int i=n;i--;) {
		if(~s[i]) {
			dp.up(s[i],s[i],dp.qry(s[i],m)+1-dp.qry(s[i],s[i]));
			dp.up(0,s[i]-1,1);
		}
		for(auto j: edge[i])
			dp.up(j+1,m,1);
	}
	cout << ans + dp.qry(0,m);
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |