# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
393996 | Berted | Salesman (IOI09_salesman) | C++14 | 492 ms | 44484 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 <iostream>
#include <algorithm>
#include <vector>
#define ll long long
#define pii pair<int, int>
#define fst first
#define snd second
const ll INF = 1e15;
const int MX = 500001;
using namespace std;
int N, U, D, S;
vector<pii> A[MX + 1];
ll ans[MX + 1], BIT[2][MX + 1];
inline void init()
{
for (int i = 0; i <= MX; i++) BIT[0][i] = BIT[1][i] = -INF;
}
inline void upd(int t, int i, ll val)
{
for (; i <= MX; i += i & (-i)) {BIT[t][i] = max(BIT[t][i], val);}
}
inline ll qry(int t, int i)
{
ll ret = -INF;
for(; i; i -= i & (-i)) {ret = max(ret, BIT[t][i]);}
return ret;
}
inline ll getAns(int x)
{
return max(qry(0, MX + 1 - x) + U * x, qry(1, x) - D * x);
}
inline void ins(int x, ll v)
{
upd(0, MX + 1 - x, v - U * x);
upd(1, x, v + D * x);
}
int main()
{
ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> U >> D >> S;
for (int i = 0; i < N; i++)
{
int T, L, M; cin >> T >> L >> M;
A[T].push_back({L, M});
}
init(); ins(S, 0);
for (int i = 1; i <= MX; i++)
{
for (int j = 0; j < A[i].size(); j++)
{
ans[j] = getAns(A[i][j].fst) + A[i][j].snd;
}
for (int j = 0; j < A[i].size(); j++)
{
ins(A[i][j].fst, ans[j]);
}
}
cout << getAns(S) << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |