제출 #808698

#제출 시각아이디문제언어결과실행 시간메모리
808698vjudge1코알라 (JOI13_koala)C++17
0 / 100
108 ms3548 KiB
#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; } 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; for (int j = k; j <= k + 1; 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; // if (i == 2) // cout << j << ' ' << id << ' ' << tmp << '\n'; maxi(res, tmp + a[i].se); } // cout << i << ' ' << k << " " << res << '\n'; ST.update(1, 0, n, i, res); pre_place = b[i]; // if (i == 1) // for (int j = 0; j <= 1; j++) // cout << ST.get(1, 0, n, j, j) << ' '; } int k = (t - pre_place) / limDis + ((t - pre_place) % limDis > 0); ll ans = -oo; for (int j = k; j <= k + 1; j++){ int id = lower_bound(b, b + n + 1, t - j * limDis) - b; ll tmp = ST.get(1, 0, n, id, n) - j * downPower; maxi(ans, tmp); } cout << ans; } int main(){ // load(); input(); solveUp(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...