#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
#define int long long
using namespace std;
const int inf=1e18;
struct ST{
vector<pair<int,int> > st;
void init(int x){
st.resize(4*x);
}
void upd(int v,int x){
st[v].fs+=x;
st[v].sc+=x;
}
void pudo(int v){
upd(2*v+1,st[v].sc);
upd(2*v+2,st[v].sc);
st[v].sc=0;
}
void pull(int v){
st[v].fs=max(st[2*v+1].fs,st[2*v+2].fs);
}
void update(int v,int L,int R,int l,int r,int k){
if(L==l && r==R){
upd(v,k);
return;
}
int m=(L+R)/2;
pudo(v);
if(r<=m){
update(2*v+1,L,m,l,r,k);
}
else if(l>m){
update(2*v+2,m+1,R,l,r,k);
}
else{
update(2*v+1,L,m,l,m,k);
update(2*v+2,m+1,R,m+1,r,k);
}
pull(v);
}
int query(int v,int L,int R,int l,int r){
if(L==l && r==R){
return st[v].fs;
}
pudo(v);
int m=(L+R)/2;
if(r<=m){
return query(2*v+1,L,m,l,r);
}
else if(l>m){
return query(2*v+2,m+1,R,l,r);
}
else{
return max(query(2*v+1,L,m,l,m),query(2*v+2,m+1,R,m+1,r));
}
}
}st;
struct BIT{
int n;
vector<int> bt;
void init(int x){
n=x;
bt.resize(n+1);
}
void update(int x,int y){
for(;x>0;x-=(x&-x)){
bt[x]+=y;
}
}
int query(int x){
int ans=0;
for(;x<=n;x+=(x&-x)){
ans+=bt[x];
}
return ans;
}
}bt,bt2;
signed main(){
AquA;
int n,m;
cin >> n >> m;
vector<int> a(n+1),b(m+1),s(n+1),t(m+1),p(n+1),q(m+1);
for(int i=1;i<=n;i++){
cin >> a[i] >> s[i] >> p[i];
a[i]+=a[i-1];
}
for(int j=1;j<=m;j++){
cin >> b[j] >> t[j] >> q[j];
b[j]+=b[j-1];
}
vector<int> oka(n+1),okb(m+1);
vector<pair<int,int> > to;
for(int i=1;i<=n;i++){
oka[i]=upper_bound(b.begin(),b.end(),s[i]-a[i])-b.begin()-1;
to.push_back({oka[i],i});
}
sort(to.begin(),to.end());
for(int i=1;i<=m;i++){
okb[i]=upper_bound(a.begin(),a.end(),t[i]-b[i])-a.begin()-1;
}
st.init(n+1);
bt.init(n);
bt2.init(n);
st.update(0,0,n,1,n,-inf);
for(int i=1;i<=n;i++){
if(oka[i]>=0){
st.update(0,0,n,0,i-1,p[i]);
bt.update(i,p[i]);
}
}
/*
for(int i=1;i<=n;i++){
cout << oka[i] << " ";
}
cout << "\n";
for(int j=1;j<=m;j++){
cout << okb[j] << " ";
}
cout << "\n";
*/
int l=0;
while(l<(int)to.size() && to[l].fs<0){
l++;
}
vector<int> dp(n+1);
for(int i=1;i<=m;i++){
if(okb[i]>=0){
st.update(0,0,n,0,okb[i],q[i]);
bt2.update(okb[i],q[i]);
}
while(l<(int)to.size() && to[l].fs==i){
int x=to[l].sc;
dp[x]=st.query(0,0,n,0,x-1)-bt.query(x+1);
st.update(0,0,n,x,x,dp[x]+inf-bt2.query(x));
st.update(0,0,n,0,x-1,-p[x]);
bt.update(x,-p[x]);
l++;
}
}
cout << st.query(0,0,n,0,n) << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
335 ms |
33308 KB |
Output is correct |
2 |
Correct |
318 ms |
32628 KB |
Output is correct |
3 |
Correct |
296 ms |
33376 KB |
Output is correct |
4 |
Correct |
269 ms |
32396 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
317 ms |
32264 KB |
Output is correct |
7 |
Correct |
74 ms |
6668 KB |
Output is correct |
8 |
Correct |
203 ms |
27072 KB |
Output is correct |
9 |
Correct |
290 ms |
33284 KB |
Output is correct |
10 |
Incorrect |
214 ms |
33372 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
335 ms |
33308 KB |
Output is correct |
2 |
Correct |
318 ms |
32628 KB |
Output is correct |
3 |
Correct |
296 ms |
33376 KB |
Output is correct |
4 |
Correct |
269 ms |
32396 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
317 ms |
32264 KB |
Output is correct |
7 |
Correct |
74 ms |
6668 KB |
Output is correct |
8 |
Correct |
203 ms |
27072 KB |
Output is correct |
9 |
Correct |
290 ms |
33284 KB |
Output is correct |
10 |
Incorrect |
214 ms |
33372 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
335 ms |
33308 KB |
Output is correct |
2 |
Correct |
318 ms |
32628 KB |
Output is correct |
3 |
Correct |
296 ms |
33376 KB |
Output is correct |
4 |
Correct |
269 ms |
32396 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
317 ms |
32264 KB |
Output is correct |
7 |
Correct |
74 ms |
6668 KB |
Output is correct |
8 |
Correct |
203 ms |
27072 KB |
Output is correct |
9 |
Correct |
290 ms |
33284 KB |
Output is correct |
10 |
Incorrect |
214 ms |
33372 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |