Language: C++

#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
#define rll register ll
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: putc;
using io :: print;
const int N=85,M=105,inf=2e9,L=325;
const ll INF=1e8;
int flag,x0[N],y0[N],lx[M],rx[M],ly[M],ry[M];
ll v0[N];
struct node{
	char op;
	int a,b;
}q[L];
inline void chmin(int &x,ri y){
	x=min(x,y);
}
inline void chmax(int &x,ri y){
	x=max(x,y);
}
namespace G{
	const int _N=(M<<1)+N,_M=(M<<1)+(N<<1); 
	const ll INF=1e18;
	int size,s,t,m,a[_M],b[_M],c[_M],d[_M],deg[_N],
	tot=1,head[_N],nxt[_M<<2],adj[_M<<2],cap[_M<<2],q[_M<<5],S,T,flow,sum,vis[_N],cur[_N];
	ll cost,dis[_N],val[_M<<2],e[_M];
	inline void addedge(ri x,ri y,ri c,rll w){
		nxt[++tot]=head[x];
		adj[head[x]=tot]=y;
		cap[tot]=c;
		val[tot]=w;
	}
	inline void Add(ri x,ri y,ri c,rll v){
		addedge(x,y,c,v);
		addedge(y,x,0,-v);
	}
	inline void add(ri x,ri y,ri lower,ri upper,rll cost){
		if(lower>upper) flag=0;
		++m;
		a[m]=x;
		b[m]=y;
		c[m]=lower;
		d[m]=upper;
		e[m]=cost;
	}
	inline void build(){
		ri i;
		cost=0;
		for(i=1;i<=m;++i)
			deg[a[i]]-=c[i],
			deg[b[i]]+=c[i],
			cost+=c[i]*e[i],
			Add(a[i],b[i],d[i]-c[i],e[i]);
		S=size+1;
		T=size+2;
		sum=0;
		for(i=1;i<=size;++i){
			if(deg[i]>0) Add(S,i, deg[i],0),sum+=deg[i];
			if(deg[i]<0) Add(i,T,-deg[i],0);
		}
		Add(t,s,inf,0);
		size+=2;
	}
	inline bool spfa(){
		ri l,r,x,y,i;
		for(i=1;i<=size;++i) dis[i]=-INF,vis[i]=0,cur[i]=head[i];
		q[l=r=1]=S;dis[S]=0; 
		while(l<=r){
			x=q[l++];vis[x]=0; 
			for(i=head[x];i;i=nxt[i])
				if(cap[i]&&dis[y=adj[i]]<dis[x]+val[i]){
					dis[y]=dis[x]+val[i];
					if(!vis[y]) q[++r]=y,vis[y]=1;
				}
		}
		return dis[T]>-INF;
	}
	inline int dfs(ri x,ri now){
		if(x==T) return now;
		vis[x]=1;
		ri y,tmp,res=0;
		for(int &i=cur[x];i;i=nxt[i])
			if(!vis[y=adj[i]]&&cap[i]&&dis[y]==dis[x]+val[i])
				if(cap[i]-=(tmp=dfs(y,min(now-res,cap[i]))),cap[i^1]+=tmp,(res+=tmp)==now)
					return vis[x]=false,res;
		return res;
	}
	inline ll costflow(){
		ri tmp;
		flow=0;
		while(spfa())
			tmp=dfs(S,inf),
			flow+=tmp,
			cost+=tmp*dis[T];
		if(flow!=sum) return -INF;
		return cost;
	}
	inline void clear(){
		tot=1;m=0;
		for(ri i=1;i<=size;++i) head[i]=deg[i]=0;
	}
}
int posx[M],posy[M];
int main(){
	ri n,m,i,k,limx,limy;
	gi(n);
	limx=limy=0;
	for(i=1;i<=n;++i)
		gi(x0[i]),gi(y0[i]),gi(v0[i]),
		limx=max(limx,x0[i]),
		limy=max(limy,y0[i]);
	gi(m);
	for(i=1;i<=m;++i){
		get(q[i].op);gi(q[i].a);gi(q[i].b);
		if(q[i].op=='L'||q[i].op=='R')
			limx=max(limx,q[i].a);
		else
			limy=max(limy,q[i].a);
	}
	rll ans=0; 
	for(k=1;k<=n;++k){
		for(i=1;i<=limx;++i)
			lx[i]=0,
			rx[i]=inf;
		for(i=1;i<=limy;++i)
			ly[i]=0,
			ry[i]=inf;
		flag=1;
		for(i=1;i<=m;++i)
			if(q[i].op=='L')
				chmin(rx[q[i].a],q[i].b);
			else if(q[i].op=='R'){
				if(q[i].a-1==0){
					if(k-q[i].b>0){
						flag=0;
						break;
					}
				}
				else
					chmax(lx[q[i].a-1],k-q[i].b);
			}
			else if(q[i].op=='D')
				chmin(ry[q[i].a],q[i].b);
			else{
				if(q[i].a-1==0){
					if(k-q[i].b>0){
						flag=0;
						break;
					}
				}
				else
					chmax(ly[q[i].a-1],k-q[i].b);
			}
		if(!flag) continue;
		for(i=1;i<=limx;++i)
			lx[i]=max(lx[i-1],lx[i]);
		for(i=limx-1;i;--i)
			rx[i]=min(rx[i+1],rx[i]);
		for(i=1;i<=limy;++i)
			ly[i]=max(ly[i-1],ly[i]);
		for(i=limy-1;i;--i)
			ry[i]=min(ry[i+1],ry[i]);
		G::size=n;
		for(i=1;i<=limx;++i)
			posx[i]=++G::size;
		for(i=1;i<=limy;++i)
			posy[i]=++G::size;
		G::s=++G::size;
		G::t=++G::size;
		G::add(G::s,posx[limx],max(k,lx[limx]),min(k,rx[limx]),0);
		for(i=limx-1;i;--i)
			G::add(posx[i+1],posx[i],lx[i],rx[i],0);
		G::add(posy[limy],G::t,ly[limy],ry[limy],0);
		for(i=1;i<limy;++i)
			G::add(posy[i],posy[i+1],ly[i],ry[i],0);
		for(i=1;i<=n;++i)
			G::add(posx[x0[i]],i,0,1,v0[i]),
			G::add(i,posy[y0[i]],0,1,0);
		if(!flag) continue;
		G::build();
		ans=max(ans,G::costflow());
		G::clear();
	}
	printf("%lld\n",ans);
	return 0;
}

Compiler output:
a.cc:49:20: error: 'int y0 [85]' redeclared as different kind of entity
   49 | int flag,x0[N],y0[N],lx[M],rx[M],ly[M],ry[M];
      |                    ^
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683,
                 from /usr/include/c++/14/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:33,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:256:1: note: previous declaration 'double y0(double)'
  256 | __MATHCALL (y0,, (_Mdouble_));
      | ^~~~~~~~~~
a.cc:55:29: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   55 | inline void chmin(int &x,ri y){
      |                             ^
a.cc:58:29: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   58 | inline void chmax(int &x,ri y){
      |                             ^
a.cc:67:32: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   67 |         inline void addedge(ri x,ri y,ri c,rll w){
      |                                ^
a.cc:67:37: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   67 |         inline void addedge(ri x,ri y,ri c,rll w){
      |                                     ^
a.cc:67:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   67 |         inline void addedge(ri x,ri y,ri c,rll w){
      |                                          ^
a.cc:67:48: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   67 |         inline void addedge(ri x,ri y,ri c,rll w){
      |                                                ^
a.cc:73:28: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   73 |         inline void Add(ri x,ri y,ri c,rll v){
      |                            ^
a.cc:73:33: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   73 |         inline void Add(ri x,ri y,ri c,rll v){
      |                                 ^
a.cc:73:38: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   73 |         inline void Add(ri x,ri y,ri c,rll v){
      |                                      ^
a.cc:73:44: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   73 |         inline void Add(ri x,ri y,ri c,rll v){
      |                                            ^
a.cc:77:28: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   77 |         inline void add(ri x,ri y,ri lower,ri upper,rll cost){
      |                            ^
a.cc:77:33: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   77 |         inline void add(ri x,ri y,ri lower,ri upper,rll cost){
      |                                 ^
a.cc:77:38: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   77 |         inline void add(ri x,ri y,ri lower,ri upper,rll cost){
      |                                      ^~~~~
a.cc:77:47: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   77 |         inline void add(ri x,ri y,ri lower,ri upper,rll cost){
      |                                               ^~~~~
a.cc:77:57: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   77 |         inline void add(ri x,ri y,ri lower,ri upper,rll cost){
      |                                                         ^~~~
a.cc: In function 'void G::build()':
a.cc:87:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   87 |                 ri i;
      |                    ^
a.cc: In function 'bool G::spfa()':
a.cc:105:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  105 |                 ri l,r,x,y,i;
      |                    ^
a.cc:105:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  105 |                 ri l,r,x,y,i;
      |                      ^
a.cc:105:24: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  105 |                 ri l,r,x,y,i;
      |                        ^
a.cc:105:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  105 |                 ri l,r,x,y,i;
      |                          ^
a.cc:105:28: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  105 |                 ri l,r,x,y,i;
      |                            ^
a.cc: At global scope:
a.cc:118:27: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  118 |         inline int dfs(ri x,ri now){
      |                           ^
a.cc:118:32: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  118 |         inline int dfs(ri x,ri now){
      |                                ^~~
a.cc: In function 'int G::dfs(int, int)':
a.cc:121:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  121 |                 ri y,tmp,res=0;
      |                    ^
a.cc:121:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  121 |                 ri y,tmp,res=0;
      |                      ^~~
a.cc:121:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  121 |                 ri y,tmp,res=0;
      |                          ^~~
a.cc: In function 'll G::costflow()':
a.cc:129:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  129 |                 ri tmp;
      |                    ^~~
a.cc: In function 'void G::clear()':
a.cc:140:24: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  140 |                 for(ri i=1;i<=size;++i) head[i]=deg[i]=0;
      |                        ^
a.cc: In function 'int main()':
a.cc:145:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  145 |         ri n,m,i,k,limx,limy;
      |            ^
a.cc:145:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  145 |         ri n,m,i,k,limx,limy;
      |              ^
a.cc:145:16: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  145 |         ri n,m,i,k,limx,limy;
      |                ^
a.cc:145:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  145 |         ri n,m,i,k,limx,limy;
      |                  ^
a.cc:145:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  145 |         ri n,m,i,k,limx,limy;
      |                    ^~~~
a.cc:145:25: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  145 |         ri n,m,i,k,limx,limy;
      |                         ^~~~
a.cc:149:34: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  149 |                 gi(x0[i]),gi(y0[i]),gi(v0[i]),
      |                                  ^
a.cc:151:35: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  151 |                 limy=max(limy,y0[i]);
      |                                   ^
a.cc:151:25: error: no matching function for call to 'max(int&, double (&)(double) noexcept)'
  151 |                 limy=max(limy,y0[i]);
      |                      ~~~^~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:151:25: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'double(double) noexcept')
  151 |                 limy=max(limy,y0[i]);
      |                      ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:151:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  151 |                 limy=max(limy,y0[i]);
      |                      ~~~^~~~~~~~~~~~
a.cc:160:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  160 |         rll ans=0;
      |             ^~~
a.cc:218:43: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  218 |                         G::add(i,posy[y0[i]],0,1,0);
      |                                           ^
a.cc:218:38: error: invalid types 'int [105][double(double) noexcept]' for array subscript
  218 |                         G::add(i,posy[y0[i]],0,1,0);
      |                                      ^
a.cc: In instantiation of 'void io::gi(I&) [with I = double(double) noexcept]':
a.cc:149:15:   required from here
  149 |                 gi(x0[i]),gi(y0[i]),gi(v0[i]),
      |                           ~~^~~~~~~
a.cc:25:24: error: assignm