#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll SZ = 1 << 17, INF = 2E18;
ll P[SZ], B[SZ], dp[SZ];
struct Seg {
ll T[SZ << 1], Z[SZ << 1];
Seg() {
fill(T, T + SZ * 2, -INF);
}
void Push(int n) {
if (n < SZ) {
Z[n * 2] += Z[n];
Z[n * 2 + 1] += Z[n];
}
T[n] += Z[n];
Z[n] = 0;
}
void Update(int L, int R, ll v, int sL = 1, int sR = SZ, int n = 1) {
Push(n);
if (R < sL || sR < L) return;
if (L <= sL && sR <= R) {
Z[n] += v;
Push(n);
return;
}
int mid = (sL + sR) >> 1;
Update(L, R, v, sL, mid, n * 2);
Update(L, R, v, mid + 1, sR, n * 2 + 1);
T[n] = max(T[n * 2], T[n * 2 + 1]);
}
ll Query(int L, int R, int sL = 1, int sR = SZ, int n = 1) {
Push(n);
if (R < sL || sR < L) return -INF;
if (L <= sL && sR <= R) return T[n];
int mid = (sL + sR) >> 1;
return max(Query(L, R, sL, mid, n * 2), Query(L, R, mid + 1, sR, n * 2 + 1));
}
} T;
int Get(vector<int>& S, int n) {
return (lower_bound(S.begin(), S.end(), n) - S.begin());
}
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;
vector<int> mod;
for (int i = 0; i <= N + 1; ++i) mod.push_back(P[i] % D);
mod.push_back(-1);
sort(mod.begin(), mod.end());
mod.erase(unique(mod.begin(), mod.end()), mod.end());
int init = Get(mod, P[0] % D);
T.Update(init, init, INF);
for (int i = 1; i <= N + 1; ++i) {
int cur = Get(mod, P[i] % D);
ll diff = P[i] - P[i - 1], mv = diff / D, more = diff % D;
T.Update(1, SZ, -mv * A);
if (more) {
int a = Get(mod, P[i - 1] % D), b = Get(mod, ((P[i - 1] % D) + more) % D);
if (a < b) T.Update(a, b - 1, -A);
else {
T.Update(a, SZ, -A);
if (1 < b) T.Update(1, b - 1, -A);
}
}
ll pv = T.Query(cur, cur);
dp[i] = T.Query(1, SZ) + B[i];
T.Update(cur, cur, -pv + dp[i]);
}
cout << dp[N + 1] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
6748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
102 ms |
9316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
126 ms |
9180 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |