Submission #655379

#TimeUsernameProblemLanguageResultExecution timeMemory
655379denniskimSalesman (IOI09_salesman)C++17
6 / 100
3099 ms21616 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef __int128 lll; typedef long double ld; #define MAX 9223372036854775807LL #define MIN -9223372036854775807LL #define INF 0x3f3f3f3f3f3f3f3f #define fi first #define se second #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define sp << " " #define en << "\n" struct GUJO { ll T, L, M; }; bool sort1(GUJO X, GUJO Y) { return X.T < Y.T; } ll n, U, D, S; GUJO a[500010]; ll dp[500010]; ll ans; int main(void) { fastio cin >> n >> U >> D >> S; a[0].T = -1; a[0].L = S; a[0].M = 0; for(ll i = 1 ; i <= n ; i++) cin >> a[i].T >> a[i].L >> a[i].M; sort(a + 1, a + 1 + n, sort1); a[n + 1].T = -1; a[n + 1].L = S; a[n + 1].M = 0; for(ll i = 1 ; i <= n + 1 ; i++) { for(ll j = 0 ; j < i ; j++) { if(a[i].L < a[j].L) dp[i] = max(dp[i], dp[j] - (a[j].L - a[i].L) * U + a[i].M); else dp[i] = max(dp[i], dp[j] - (a[i].L - a[j].L) * D + a[i].M); } } cout << dp[n + 1]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...