1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| #include "iostream" #include "algorithm" #include "cstring" #include "cstdio" #include "cmath" #include "vector" #include "map" #include "set" #include "queue" #include "stack" #include "cassert" #include "string" using namespace std; #define MAXN 500006
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedef long long ll; typedef unsigned long long u64; const int P = 924844033; int n , U , D , s;
vector<pii> S[MAXN]; int dy , mx; int dp[MAXN] , pd[MAXN] , f[MAXN]; struct BIT { int T[MAXN]; BIT( ) { memset( T , -0x3f , sizeof T ); } void pu( int x , int c ) { while( x <= mx ) T[x] = max( T[x] , c ) , x += x & -x; } int pmx( int x ) { int ret = -0x3f3f3f3f; while( x > 0 ) ret = max( ret , T[x] ) , x -= x & -x; return ret; } } T[2] ;
void solve() { cin >> n >> U >> D >> s; mx = s; rep( i , 1 , n ) { int t , l , m; dy = max( dy , t ); scanf("%d%d%d",&t,&l,&m); S[t].eb( mp( l , m ) ); mx = max( mx , l ); } T[0].pu( s , s * D ) , T[1].pu( mx - s + 1 , - s * U ); S[dy + 1].eb( mp( s , 0 ) ); ++ dy; int res = 0; rep( i , 1 , dy ) if( S[i].size() ) { sort( all( S[i] ) ); int m = S[i].size(); for( int j = 1 ; j <= m ; ++ j ) { pii u = S[i][j - 1]; f[j] = max( T[1].pmx( mx - u.fi + 1 ) + u.fi * U , T[0].pmx( u.fi ) - u.fi * D ) + u.se; } dp[1] = f[1]; rep( j , 2 , m ) dp[j] = max( f[j] , dp[j - 1] - D * ( S[i][j - 1].fi - S[i][j - 2].fi ) + S[i][j - 1].se ); pd[m] = f[m]; per( j , m - 1 , 1 ) pd[j] = max( f[j] , pd[j + 1] - U * ( S[i][j].fi - S[i][j - 1].fi ) + S[i][j - 1].se ); rep( j , 1 , m ) { f[j] = max( pd[j] , dp[j] ); res = max( res , f[j] ); pii u = S[i][j - 1]; T[0].pu( u.fi , f[j] + u.fi * D ) , T[1].pu( mx - u.fi + 1 , f[j] - u.fi * U ); } } printf("%d\n",f[1]); }
signed main() {
solve(); }
|