Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair < int , int > pii;
typedef pair < LL , int > pli;
const LL INF=(LL)(1e15+5),LINF=(LL)(2e18+5);
int n,m,x[80],y[80],px[80],py[80];
LL v[80];
char readch(){
	char c=getchar();
	while(c!='L' && c!='R' && c!='U' && c!='D'){
		c=getchar();
	}
	return c;
}
namespace flows{
	struct edge{
		int v,f,r;
		LL c;
		void set(int V,int F,int R,LL C){
			v=V;f=F;r=R;c=C;
		}
	}tmp;
	vector < edge > adj[505];
	priority_queue < pli > pq;
	int predv[505],prede[505],flow;
	LL f[505],dis[505],cost;
	void init(){
		int i;
		for(i=0;i<505;++i) adj[i].clear();
		memset(f,0,sizeof(f));
		flow=0;cost=0ll;
	}
	void addedge(int u,int v,int f,LL c){
		tmp.set(v,f,(int)adj[v].size(),c);
		adj[u].push_back(tmp);
		tmp.set(u,0,(int)adj[u].size()-1,-c);
		adj[v].push_back(tmp);
	}
	void dijkstra(){
		int i,j,k;
		fill(dis,dis+505,LINF);
		dis[0]=0ll;
		pq.push(mpr(0ll,0));
		while(!pq.empty()){
			LL D=-pq.top().first;
			int cur=pq.top().second;
			pq.pop();
			if(dis[cur]!=D) continue;
			for(i=0;i<(int)adj[cur].size();++i){
				if(!adj[cur][i].f) continue;
				int v=adj[cur][i].v;
				LL l=adj[cur][i].c+f[cur]-f[v];
				if(D+l<dis[v]){
					dis[v]=D+l;
					predv[v]=cur;
					preve[v]=i;
					pq.push(mpr(-dis[v],v));
				}
			}
		}
		memcpy(f,dis,sizeof(f));
	}
	void mincostflow(){
		int i,j,k;
		
	}
};
bool cmpx(int a,int b){
	return x[a]<x[b];
}
bool cmpy(int a,int b){
	return y[a]<y[b];
}
char TP[405];
int D[405],V[405];
vector < pii > consx,consy;
LL solve(int tot){
	int i,j,k;
	consx.clear();
	consy.clear();
	for(i=0;i<m;++i){
		if(TP[i]=='L')
			consx.push_back(mpr(D[i],V[i]));
		else if(TP[i]=='R' && V[i]<tot)
			consx.push_back(mpr(D[i]-1,-tot+V[i]));
		else if(TP[i]=='D')
			consy.push_back(mpr(D[i],V[i]));
		else if(TP[i]=='U' && V[i]<tot)
			consy.push_back(mpr(D[i]-1,-tot+V[i]));
	}
	sort(consx.begin(),consx.end());
	sort(consy.begin(),consy.end());
	flows::init();
	// 0: super source  1: original source  2: extra source
	flows::addedge(0,1,tot,0);
	flows::addedge(4,3,tot,0);
	int extraflow=0,ptr=n-1,pr=1,SX=(int)consx.size();
	for(i=SX-1;i>=0;--i){
		int d=consx[i].first,f=consx[i].second;
		while(ptr>=0 && x[px[ptr]]>d){
			flows::addedge(pr,6+SX+px[ptr],1,0);
			--ptr;
		}
		if(f<0){
			f=-f;
			extraflow+=f;
			flows::addedge(2,i+6,f,0);
			flows::addedge(pr,5,f,0);
			flows::addedge(pr,i+6,tot-f,0);
		}
		else flows::addedge(pr,i+6,f);
		pr=i+6;
	}
	while(ptr>=0){
		flows::addedge(pr,6+SX+px[ptr],1,0);
		--ptr;
	}
	for(i=0;i<n;++i){
		flows::addedge(6+SX+i,6+SX+n+i,1,INF-v[i]);
	}
	ptr=0;pr=-1;
	int pf;
	for(i=0;i<(int)consy.size();++i){
		int d=consy[i].first,cur=6+SX+n*2+i;
		while(ptr<n && y[py[ptr]]<=d){
			flows::addedge(6+SX+n+py[ptr],cur,1,0);
			++ptr;
		}
		if(pr!=-1){
			if(pf<0){
				pf=-pf;
				extraflow+=pf;
				flows::addedge(2,cur,pf,0);
				flows::addedge(pr,5,pf,0);
				flows::addedge(pr,cur,tot-pf,0);
			}
			else flows::addedge(pr,cur,pf,0);
		}
		pf=consy[i].second;
		pr=cur;
	}
	flows::addedge(2,0,extraflow,0);
	flows::addedge(5,3,extraflow,0);
	flows::mincostflow();
	if(flows::flow==extraflow+tot)
		return INF*(LL)tot-flows::cost;
	return 0ll;
}
int main(){
	int i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;++i){
		scanf("%d%d%lld",x+i,y+i,v+i);
		--x[i];--y[i];
		px[i]=i;
		py[i]=i;
	}
	scanf("%d",&m);
	for(i=0;i<m;++i){
		TP[i]=readch();
		scanf("%d%d",D+i,V+i);
		--D[i];
	}
	sort(px,px+n,cmpx);
	sort(py,py+n,cmpy);
	LL res=0ll;
	for(i=0;i<=n;++i){
		UMAX(res,solve(i));
	}
	printf("%lld\n",res);
	return 0;
}

Compiler output:
a.cc: In function 'void flows::dijkstra()':
a.cc:44:25: error: 'mpr' was not declared in this scope
   44 |                 pq.push(mpr(0ll,0));
      |                         ^~~
a.cc:57:41: error: 'preve' was not declared in this scope; did you mean 'prede'?
   57 |                                         preve[v]=i;
      |                                         ^~~~~
      |                                         prede
a.cc: In function 'LL solve(int)':
a.cc:84:41: error: 'mpr' was not declared in this scope
   84 |                         consx.push_back(mpr(D[i],V[i]));
      |                                         ^~~
a.cc:86:41: error: 'mpr' was not declared in this scope
   86 |                         consx.push_back(mpr(D[i]-1,-tot+V[i]));
      |                                         ^~~
a.cc:88:41: error: 'mpr' was not declared in this scope
   88 |                         consy.push_back(mpr(D[i],V[i]));
      |                                         ^~~
a.cc:90:41: error: 'mpr' was not declared in this scope
   90 |                         consy.push_back(mpr(D[i]-1,-tot+V[i]));
      |                                         ^~~
a.cc:112:36: error: too few arguments to function 'void flows::addedge(int, int, int, LL)'
  112 |                 else flows::addedge(pr,i+6,f);
      |                      ~~~~~~~~~~~~~~^~~~~~~~~~
a.cc:34:14: note: declared here
   34 |         void addedge(int u,int v,int f,LL c){
      |              ^~~~~~~
a.cc: In function 'int main()':
a.cc:169:17: error: 'UMAX' was not declared in this scope
  169 |                 UMAX(res,solve(i));
      |                 ^~~~