# 【PA2014】【BZOJ3716】Muzeum

403 篇文章 0 订阅
32 篇文章 0 订阅

Description

Input

Output

Sample Input

5 3

2 3

2 6 2

5 1 3

5 5 8

7 3 4

8 6 1

3 8 3

4 3 5

5 7 6
Sample Output

6

HINT

Source

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#define MAXN 200010
#define GET (ch>='0'&&ch<='9')
#define LL long long
using namespace std;
int n,m;
LL w,h,x,y,v,ans;
struct Point
{
LL x,y,v;
bool operator <(const Point& a)const    {return x==a.x?y<a.y:x<a.x;}
}s[MAXN<<1];
struct node
{
LL y,v;
bool operator <(const node& a)const {return y<=a.y;}
};
void in(LL &x)
{
char ch=getchar();x=0;LL flag=1;
while (!GET)    flag=ch=='-'?-1:1,ch=getchar();
while (GET) x=x*10+ch-'0',ch=getchar();x*=flag;
}
set<node>   S;
set<node>::iterator p;
int main()
{
scanf("%d%d",&n,&m);in(w);in(h);
for (int i=1;i<=n;i++)  in(x),in(y),in(v),x*=h,y*=w,s[i].x=x+y,s[i].y=y-x,s[i].v=v;
for (int i=1;i<=m;i++)  in(x),in(y),in(v),x*=h,y*=w,s[i+n].x=x+y,s[i+n].y=y-x,s[i+n].v=-v;
sort(s+1,s+n+m+1);
for (int i=1;i<=n+m;i++)
for (y=s[i].y,v=s[i].v;v;ans-=p->v,v+=p->v,S.erase(p))
{
p=S.lower_bound((node){y,0});
if (p==S.end()||p->y!=y)
{
if (v>0)    {S.insert((node){y,v});ans+=v;break;}
else    if (p==S.begin())   break;
else    y=(--p)->y;
}
}
cout<<ans<<endl;
}
• 2
点赞
• 0
评论
• 0
收藏
• 一键三连
• 扫一扫，分享海报

07-14 35
05-20 42

03-26 332
03-04 71
07-20 230
07-17 2369
10-09 337
08-03 27