# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
228819 | osaaateiasavtnl | Salesman (IOI09_salesman) | C++14 | 3089 ms | 52588 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 ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 5e5 + 7;
const int INF = 1e18;
/*
struct Fen {
int f[N];
void init() {
for (int i = 0; i < N; ++i)
f[i] = -INF;
}
void add(int i, int x) {
for (; i < N; i |= i + 1)
f[i] = max(f[i], x);
}
int get(int i) {
int ans = -INF;
for (; i >= 0; i &= i + 1, --i)
ans = max(ans, f[i]);
return ans;
}
} l, r; // l - relax from l, r - relax from r
*/
int n, U, D, S;
struct Fair {
int day, pos, cost;
} a[N];
int dp[N];
bool comp(Fair a, Fair b) {
return a.day < b.day;
}
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
cin >> n >> U >> D >> S;
set <int> ms;
for (int i = 1; i <= n; ++i) {
cin >> a[i].day >> a[i].pos >> a[i].cost;
ms.insert(a[i].day);
}
if (ms.size() < n) {
exit(1);
}
for (int i = 0; i < N; ++i)
dp[i] = -INF;
dp[S] = 0;
sort(a + 1, a + n + 1, comp);
vector <int> c = {S};
for (int i = 1; i <= n; ++i)
c.app(a[i].pos);
sort(all(c));
c.resize(unique(all(c)) - c.begin());
for (int i = 1; i <= n; ++i) {
int nn = -INF;
for (int x : c) {
if (dp[x] != -INF) {
if (x < a[i].pos)
nn = max(nn, dp[x] - (a[i].pos - x) * D + a[i].cost);
else
nn = max(nn, dp[x] - (x - a[i].pos) * U + a[i].cost);
}
}
dp[a[i].pos] = max(dp[a[i].pos], nn);
}
int ans = 0;
for (int i = 0; i <= S; ++i)
ans = max(ans, dp[i] - D * (S - i));
for (int i = S; i < N; ++i)
ans = max(ans, dp[i] - U * (i - S));
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |