Analysis
Establish a dot and connect a flow to each job to the amount of money that the job can make.
Each job connects to the machine it needs at a rental rate.
Each machine connects an edge with a flow rate for the purchase cost to the confluence point.
Then run the maximum flow
As to why this can be done
Sure Analogy with this question
Code
#include<bits/stdc++.h> #define in read() #define re register using namespace std; inline int read(){ char ch;int f=1,res=0; while((ch=getchar())<'0'||ch>'9') if(ch=='-') f=-1; while(ch>='0'&&ch<='9'){ res=(res<<1)+(res<<3)+(ch^48); ch=getchar(); } return f==1?res:-res; } const int inf = 1e9; const int N=3000,M=4e6; int n,m; int S,T; int lev[N],cur[N]; int nxt[M],to[M],cap[M],ecnt=1,head[N]; inline void add(int x,int y,int w){ nxt[++ecnt]=head[x];head[x]=ecnt;to[ecnt]=y;cap[ecnt]=w; nxt[++ecnt]=head[y];head[y]=ecnt;to[ecnt]=x;cap[ecnt]=0; } bool bfs(){ queue<int> q; for(re int i=S;i<=T;++i) lev[i]=-1,cur[i]=head[i]; q.push(S);lev[S]=0; while(!q.empty()){ int u=q.front(); q.pop(); for(re int e=head[u];e;e=nxt[e]){ int v=to[e]; if(lev[v]!=-1||cap[e]<=0) continue; lev[v]=lev[u]+1; if(v==T) return 1; q.push(v); } } return 0; } int dinic(int u,int flow){ if(u==T) return flow; int delta,res=0; for(re int &e=cur[u];e;e=nxt[e]){ int v=to[e]; if(lev[v]>lev[u]&&cap[e]){ delta=dinic(v,min(flow-res,cap[e])); if(delta){ cap[e]-=delta;cap[e^1]+=delta; res+=delta;if(res==flow) return res; } } } return res; } int main(){ int sum=0; n=in;m=in;S=0;T=n+m+1; for(re int i=1;i<=n;++i){ int get=in,num=in; add(0,i,get);sum+=get; for(re int j=1;j<=num;++j){ int id=in,c=in; add(i,id+n,c); } } for(re int i=1;i<=m;++i){ int v=in; add(n+i,T,v); } int maxflow=0; while(bfs()) maxflow+=dinic(S,inf); cout<<sum-maxflow; return 0; }
Epilogue
stO hxy Orz
(Thanks to dalao for taking me to fly ())
Solving the problem of "simple construction"
But... I didn't think of it at first.
I want to give up. Look at the code.
But%% hxy%% encourage me to think about it.
Then ~ ~ ~
Hee-hee, same Space Flight Program That's it.
Sure to see more, think more!!!