Language: C++

#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
typedef pair<int,int> P;
struct edge {int to,cap,cost,rev;};
const int MAX_V=6100,INF=1e9;
int V;			//??£??\!!
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];
int top[MAX_V];
int s,t,l,r;
void add_edge(int from, int to, int cap, int cost){
//	printf("%d->%d  cap=%d,cost=%d\n",from,to,cap,cost);
	edge e1=edge(to,cap,cost,G[to].size()),e2=edge(from,0,-cost,G[from].size());
	G[from].push_back(e1);
	G[to].push_back(e2);
}
int min_cost_flow(int s, int t, int f){
	int res=0;
	fill(h,h+V,0);
	rep(i,V){
		int v=top[i];
		rep(j,G[v].size()){
			edge &e=G[v][j];
			if(e.cap==0) continue;
			int u=e.to;
			h[u]=min(h[u],h[v]+e.cost);
		}
	}
//	rep(i,V) printf("h[%d]=%d\n",i,h[i]);
	while(f>0){
		priority_queue< P,vector<P>,greater<P> > que;
		fill(dist,dist+V,INF);
		dist[s]=0;
		que.push(P(0,s));
		while(!que.empty()){
			P p=que.top();
			que.pop();
			int v=p.second;
			if(dist[v]<p.first) continue;
			for(int i=0;i<G[v].size();i++){
				edge &e=G[v][i];
				if(e.cap>0 && dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
					dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
					prevv[e.to]=v;
					preve[e.to]=i;
					que.push(P(dist[e.to],e.to));
				}
			}
		}
		if(dist[t]==INF) return -1;
		for(int v=0;v<V;v++) h[v]+=dist[v];
		int d=f;
		for(int v=t;v!=s;v=prevv[v]){
			d=min(d,G[prevv[v]][preve[v]].cap);
		}
		f-=d;
		res+=d*h[t];
		for(int v=t;v!=s;v=prevv[v]){
			edge &e=G[prevv[v]][preve[v]];
			e.cap-=d;
			G[v][e.rev].cap+=d;
		}
	}
	return res;
}
int X[3000],T[3000],p[3000];
vector<P> id;
int main(){
	int N,speed,xl,xr;
	scanf("%d%d%d%d",&N,&speed,&xl,&xr);
	rep(i,N) scanf("%d%d%d",X+i,T+i,p+i);
	s=2*N,t=s+1,l=s+2,r=s+3;
	V=r+1;
	rep(i,N){
		id.pb(P(T[i]*2,i));
		id.pb(P(T[i]*2+1,i+N));
	}
	id.pb(P(-2,s));
	id.pb(P(-1,l));
	id.pb(P(-1,r));
	id.pb(P(INF,t));
	sort(all(id));
	rep(i,V) top[i]=id[i].sc;
	rep(i,N) add_edge(i,i+N,1,-p[i]),add_edge(i,i+N,1,0);
	rep(i,N) rep(j,N){
		if(i==j) continue;
		if((T[j]-T[i])*speed>=abs(X[j]-X[i])) add_edge(i+N,j,2,0);
	}
	rep(i,N){
		if(T[i]*speed>=abs(X[i]-xl)) add_edge(l,i,1,0);
		if(T[i]*speed>=abs(X[i]-xr)) add_edge(r,i,1,0);
	}
	rep(i,N) add_edge(i+N,t,2,0);
	add_edge(s,t,2,0);
	add_edge(s,l,1,0);
	add_edge(s,r,1,0);
	cout<<-min_cost_flow(s,t,2)<<endl;
}

Compiler output:
a.cc: In function 'void add_edge(int, int, int, int)':
a.cc:29:46: error: no matching function for call to 'edge::edge(int&, int&, int&, std::vector<edge>::size_type)'
   29 |         edge e1=edge(to,cap,cost,G[to].size()),e2=edge(from,0,-cost,G[from].size());
      |                                              ^
a.cc:18:8: note: candidate: 'edge::edge()'
   18 | struct edge {int to,cap,cost,rev;};
      |        ^~~~
a.cc:18:8: note:   candidate expects 0 arguments, 4 provided
a.cc:18:8: note: candidate: 'constexpr edge::edge(const edge&)'
a.cc:18:8: note:   candidate expects 1 argument, 4 provided
a.cc:18:8: note: candidate: 'constexpr edge::edge(edge&&)'
a.cc:18:8: note:   candidate expects 1 argument, 4 provided
a.cc:31:25: error: 'e2' was not declared in this scope; did you mean 'e1'?
   31 |         G[to].push_back(e2);
      |                         ^~
      |                         e1