# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
861607 | sleepntsheep | Salesman (IOI09_salesman) | C++17 | 285 ms | 31536 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 <cstdio>
#include <cstring>
#include <cassert>
#include <string>
#include <deque>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
using ll=long long;
using ld = long double;
#define N 555555
#define ALL(x) x.begin(), x.end()
/*
*
*/
const ll X = 500005;
int n, d, u, s;
struct binarytree
{
ll t[X*2];
binarytree() {memset(t,0xbf,sizeof t);}
ll qry(int l, int r)
{
ll z = -1e18;
for (l+=X,r+=X+1;l<r;l/=2,r/=2){
if(l&1)z=max(z,t[l++]);
if(r&1)z=max(t[--r],z);
}
return z;
}
void upd(int p, int k)
{
for(t[p+=X]=k;p/=2;)t[p]=max(t[p*2],t[p*2+1]);
}
} thi, tlo;
struct fair
{
int date, pos, money;
bool operator<(const fair &o) const { return date<o.date; }
} a[N];
void upd(ll pos, ll val)
{
thi.upd(pos, val - u * pos);
tlo.upd(pos, val - (X - pos) * d);
}
ll cost(int pos)
{
return max(thi.qry(pos, X-1) + u * pos, tlo.qry(0, pos) + (X - pos) * d);
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n >> u >> d >> s;
for (int i = 0; i < n; ++i) cin >> a[i].date >> a[i].pos >> a[i].money;
sort(a, a+n);
upd(s, 0);
for (auto i = 0; i < n; ++i)
{
auto [date,pos,money] = a[i];
upd(pos, money + cost(pos));
}
cout << cost(s);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |