# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
733417 | penguin133 | Salesman (IOI09_salesman) | C++17 | 3078 ms | 21240 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, u, d, s;
int dp[500005];
pii A[500005];
void solve(){
cin >> n >> u >> d >> s;
for(int i=1;i<=n;i++){
cin >> A[i].fi >> A[i].se.fi >> A[i].se.se;
}
sort(A+1, A+n+1);
A[0].se.fi = s;
A[n+1].se.fi = s;
for(int i=1;i<=n+1;i++){
for(int j=i-1;j>=0;j--){
int cst;
if(A[j].se.fi > A[i].se.fi)cst = d * (A[j].se.fi - A[i].se.fi);
else cst = u * (A[i].se.fi - A[j].se.fi);
dp[i] = max(dp[i], dp[j] - cst + A[i].se.se);
}
}
cout << dp[n+1];
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |