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>
#define ll long long
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) ((1LL) << (i))
using namespace std;
const ll inf = 1e18+7;
const long mod = 1e9+7;
const long Nmax = 1e5+7;
int fr, to, d, cost, n;
ll dp[Nmax], st[4 * Nmax];
int t[Nmax], b[Nmax];
void update(int id, int l, int r, int i, int v)
{
if (l > i || r < i) return;
if (l == r)
{
st[id] = v;
return;
}
int mid = (l + r) >> 1;
update(id * 2, l, mid, i, v);
update(id * 2 + 1, mid + 1, r, i, v);
st[id] = max(st[id * 2], st[id * 2 + 1]);
}
ll get_max(int id, int l, int r, int u, int v)
{
if (l > v || r < u) return -inf;
if (l >= u && r <= v) return st[id];
int mid = (l + r) >> 1;
return max(get_max(id * 2, l, mid, u, v), get_max(id * 2 + 1, mid + 1, r, u, v));
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("name.inp","r",stdin);
//freopen("name.out","w",stdout);
cin >> fr >> to >> d >> cost >> n;
t[n + 2] = to;
t[1] = fr;
for (int i = 2; i <= n + 1; i++) cin >> t[i] >> b[i];
n += 2;
memset(dp, -0x3f, sizeof dp);
dp[1] = 0;
b[1] = 0;
b[n] = 0;
for (int i = 2; i <= n; i++)
{
for (int j = 1; j < i; j++)
{
int dis = t[i] - t[j];
int times = dis / d;
if (dis % d != 0) times++;
ll total_cost = 1LL * times * cost;
dp[i] = max(dp[i], dp[j] - total_cost + b[i]);
}
}
cout << dp[n];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |