46 篇文章 0 订阅
51 篇文章 0 订阅
6 篇文章 0 订阅

1<=n,m<=200000

代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#define mp(x,y) make_pair(x,y)
using namespace std;

typedef long long LL;
typedef pair<LL,LL> pi;

const int N=200005;

int n,m;
LL w,h;
struct data{LL x,y,v;}a[N],b[N];
multiset<pi> se;
multiset<pi>::iterator it;

bool cmp(data a,data b)
{
return a.x<b.x;
}

int main()
{
scanf("%d%d",&n,&m);
scanf("%lld%lld",&w,&h);
LL ans=0;
for (int i=1;i<=n;i++)
{
LL x,y,v;scanf("%lld%lld%lld",&x,&y,&v);
x*=h;y*=w;a[i].x=x+y;a[i].y=x-y;a[i].v=v;ans+=v;
}
for (int i=1;i<=m;i++)
{
LL x,y,v;scanf("%lld%lld%lld",&x,&y,&v);
x*=h;y*=w;b[i].x=x+y;b[i].y=x-y;b[i].v=v;
}
sort(a+1,a+n+1,cmp);
sort(b+1,b+m+1,cmp);
int p=1;
for (int i=1;i<=m;i++)
{
while (p<=n&&a[p].x<=b[i].x) se.insert(mp(a[p].y,a[p].v)),p++;
it=se.lower_bound(mp(b[i].y,0));LL ret=b[i].v;
while (ret&&it!=se.end())
{
pi u=*it;se.erase(it);
int f=min(u.second,ret);
ret-=f;u.second-=f;ans-=f;
if (u.second) se.insert(u);
else it=se.lower_bound(mp(b[i].y,0));
}
}
printf("%lld",ans);
return 0;
}
• 0
点赞
• 0
评论
• 0
收藏
• 一键三连
• 扫一扫，分享海报

07-14 34
05-20 41

03-26 331
03-04 70
07-20 230
09-18 37
07-16 200
10-09 337
08-03 27
03-27 674
04-26 673
11-28 531