#include "train.h"
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;
#define f first
#define s second
#define eb emplace_back
#define sz(x) (int)x.size()
#define add(x,y) ((x+y)%md)
#define Add(x,y) (x=add(x,y))
#define mul(x,y) ((x*y)%md)
#define Mul(x,y) (x=mul(x,y))
template<class T> T chmn(T &x,T y){ return x=min(x,y); }
template<class T> T chmx(T &x,T y){ return x=max(x,y); }
const int inf=1e9;
const ll linf=1e18;
const ll md=1e9+7;
vector<pair<ll,int>> dp[100005];
long long solve(int N, int M, int W, std::vector<int> T, std::vector<int> X, std::vector<int> Y,
std::vector<int> A, std::vector<int> B, std::vector<int> C, std::vector<int> L,
std::vector<int> R) {
//
dp[0].eb(0,-1);
vector<int> v(M);
iota(v.begin(),v.end(),0);
sort(v.begin(),v.end(),[&](const int &l,const int &r){ return B[l]==B[r] ? A[l]<A[r] : B[l]<B[r]; });
for(auto &i:v){
int l=0,r=sz(dp[X[i]])-1;
ll cost=linf;
for(int j=l;j<=r;++j) if(dp[X[i]][j].s <= A[i]) chmn(cost, dp[X[i]][j].f);
if(cost<linf){
cost+=C[i];
dp[Y[i]].eb(cost,B[i]);
}
}
if(dp[N-1].empty()) return -1;
ll res=1e18;
for(auto &[c,b]:dp[N-1]) chmn(res,c);
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |