이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pill pair<int,ll>
#define mem(a, b) memset(a, b, sizeof(a))
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define name "test"
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
template <typename T1, typename T2> bool maxi(T1 &a, T2 b){if (a < b){a = b; return 1;} return 0;}
template <typename T1, typename T2> bool mini(T1 &a, T2 b){if (a > b){a = b; return 1;} return 0;}
struct SEGTREE{
ll val[N << 2];
SEGTREE(){};
void update(int id, int l, int r, int i, ll x){
if (l > i || r < i) return;
if (l == r) return void(val[id] = x);
int m = (l + r) >> 1;
if (m >= i) update(id << 1, l, m, i, x);
else update(id << 1 | 1, m + 1, r, i, x);
val[id] = max(val[id << 1], val[id << 1 | 1]);
}
ll get(int id, int l, int r, int u, int v){
if (l > v || r < u) return -oo;
if (l >= u && r <= v) return val[id];
int m = (l + r) >> 1;
return max(get(id << 1, l, m, u, v), get(id << 1 | 1, m + 1, r, u, v));
}
} ST;
int s, t;
int limDis, downPower, n;
int b[N];
pii a[N];
void input(){
cin >> s >> t >> limDis >> downPower >> n;
for (int i = 1; i <= n; i++)
cin >> a[i].fi >> a[i].se;
}
void prepare(){
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++)
b[i] = a[i].fi;
}
int update(ll &res, int i, int j){
int id = lower_bound(b, b + n + 1, b[i] - j * limDis) - b;
ll tmp = ST.get(1, 0, n, id, i - 1) - downPower * j;
maxi(res, tmp + a[i].se);
return id - 1;
}
void solveUp(){
prepare();
int pre_place = s;
b[0] = s;
for (int i = 1; i <= n; i++){
int k = (b[i] - pre_place) / limDis + ((b[i] - pre_place) % limDis > 0);
ll res = -oo;
int id = update(res, i, k);
if (id >= 0){
k = (b[i] - b[id]) / limDis + ((b[i] - b[id]) % limDis > 0);
update(res, i, k);
}
ST.update(1, 0, n, i, res);
pre_place = b[i];
}
int k = (t - pre_place) / limDis + ((t - pre_place) % limDis > 0);
ll ans = -oo;
int id = lower_bound(b, b + n + 1, t - k * limDis) - b;
ll tmp = ST.get(1, 0, n, id, n) - k * downPower;
maxi(ans, tmp);
id--;
if (id >= 0){
k = (t - b[id]) / limDis + ((t - b[id]) % limDis > 0);
id = lower_bound(b, b + n + 1, t - k * limDis) - b;
tmp = ST.get(1, 0, n, id, n) - k * downPower;
maxi(ans, tmp);
}
cout << ans;
}
int main(){
// load();
input();
solveUp();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |