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 pii pair<ll, ll>
typedef long long ll;
using namespace std;
const int MAX = 100007;
ll P[MAX], B[MAX], dp[MAX];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
ll SP, EP, D, A, N;
cin >> SP >> EP >> D >> A >> N;
for (int i = 1; i <= N; ++i) cin >> P[i] >> B[i];
P[0] = SP, P[N + 1] = EP;
map<ll, ll> pv;
memset(dp, 0xf3, sizeof(dp));
pv[P[0] % D] = 0; dp[0] = 0;
for (int i = 1; i <= N + 1; ++i) {
for (auto [_, p] : pv) dp[i] = max(dp[i], dp[p] - (P[i] - P[p] + D - 1) / D * A);
dp[i] += B[i];
pv[P[i] % D] = i;
}
cout << dp[N + 1] << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |