#include <bits/stdc++.h>
using namespace std;
const int N = 100'000 + 10;
int k, m, d, a, n;
int t[N], b[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 >> t[i] >> b[i];
t[0] = k, t[n + 1] = m;
auto cal = [&](int i, int j) {
return 1ll * ((t[j] - t[i] - 1) / d + 1) * a;
};
memset(f, -14, sizeof f);
f[0] = 0;
for (int i = 1; i <= n + 1; ++i) {
for (int j = 0; j < i; ++j) {
long long energy = f[j] - cal(j, i) + b[i];
f[i] = max(f[i], energy);
}
}
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... |