# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
511196 | 600Mihnea | Salesman (IOI09_salesman) | C++17 | 3095 ms | 12448 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;
const int N = (int) 5e5 + 7;
const int INF = (int) 1e9 + 7;
int n, uuu, ddd, pay;
int t[N];
int x[N];
int g[N];
int dp[N];
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
///freopen ("input", "r", stdin);
cin >> n >> uuu >> ddd >> x[0];
pay = uuu + ddd;
for (int i = 1; i <= n; i++) {
cin >> t[i] >> x[i] >> g[i];
g[i] *= 2;
dp[i] = -INF;
}
t[n + 1] = (int) 5e5 + 1;
x[n + 1] = x[0];
vector<pair<int, int>> ord;
for (int i = 0; i <= n; i++) {
ord.push_back({t[i], i});
}
sort(ord.begin(), ord.end());
for (auto &it : ord) {
int i = it.second;
dp[i] += g[i];
///cout << i << " : " << dp[i] << "\n";
for (int j = 0; j <= n + 1; j++) {
if (t[i] < t[j]) {
int dist = abs(x[i] - x[j]);
if (x[i] < x[j]) {
dp[j] = max(dp[j], dp[i] - pay * dist);
} else {
dp[j] = max(dp[j], dp[i] - pay * dist);
}
}
}
}
cout << dp[n + 1] / 2 << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |