# 【BZOJ3716】[PA2014]Muzeum（贪心，网络流）

BZOJ

## 题解

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
#define MAX 200200
#define ll long long
#define pi pair<ll,ll>
#define mp make_pair
{
int x=0;bool t=false;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=true,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return t?-x:x;
}
struct Node{ll x,y,v;}a[MAX],b[MAX];
bool operator<(Node a,Node b){return a.x<b.x;}
ll ans;int n,m,w,h;
set<pi> S;
int main()
{
for(int i=1;i<=n;++i)
{
a[i]=(Node){x+y,x-y,v};ans+=v;
}
for(int i=1;i<=m;++i)
{
b[i]=(Node){x+y,x-y,v};
}
sort(&a[1],&a[n+1]);sort(&b[1],&b[m+1]);
for(int i=1,j=1;i<=m;++i)
{
while(j<=n&&a[j].x<=b[i].x)S.insert(mp(a[j].y,a[j].v)),++j;
set<pi>::iterator it=S.lower_bound(mp(b[i].y,0));
ll flow=b[i].v;
while(flow&&it!=S.end())
{
pi q=*it;S.erase(it);
ll d=min(q.second,flow);
flow-=d;q.second-=d;ans-=d;
if(q.second)S.insert(q);
else it=S.lower_bound(mp(b[i].y,0));
}
}
printf("%lld\n",ans);
return 0;
}

posted @ 2019-03-21 17:50  小蒟蒻yyb  阅读(328)  评论(0编辑  收藏  举报