#include <bits/stdc++.h>
using namespace std;
const int N = 100'000 + 10;
const long long MAX = 2'000'000'000'000'000'000;
int k, m, d, a, n;
int pos[N], add[N];
long long f[N];
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> k >> m >> d >> a >> n;
for (int i = 1; i <= n; ++i) cin >> pos[i] >> add[i];
pos[0] = k, pos[n + 1] = m;
fill(f + 1, f + n + 2, -MAX);
for (int i = 1; i <= n + 1; ++i) {
for (int j = 0; j < i; ++j) {
f[i] = max(f[i], f[j] - 1ll * ((pos[i] - pos[j] - 1) / d + 1) * a + add[i]);
}
}
cout << f[n + 1] << "\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... |