Submission #372678

# Submission time Handle Problem Language Result Execution time Memory
372678 2021-03-01T09:43:07 Z phathnv 코알라 (JOI13_koala) C++11
0 / 100
141 ms 3820 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 1e5 + 1;
const ll INF = 1e18;

int k, m, d, a, n;
pair<int, int> t[N];

struct segTree{
    int n, a;
    vector <int> vals;
    vector <ll> maxV;
    segTree(const vector <int> &_vals, int _a){
        n = _vals.size();
        a = _a;
        vals = _vals;
        maxV.assign(n * 4 + 1, -INF);
    }
    void update(int id, int l, int r, int u, int v, ll val){
        if (v < l || r < u)
            return;
        if (u <= l && r <= v){
            maxV[id] = max(maxV[id], val);
            return;
        }
        int mid = (l + r) >> 1;
        update(id << 1, l, mid, u, v, val);
        update(id << 1 | 1, mid + 1, r, u, v, val);
    }
    ll get(int id, int l, int r, int pos){
        if (pos < l || r < pos)
            return -INF;
        ll res = maxV[id];
        if (l == r)
            return res;
        int mid = (l + r) >> 1;
        res = max(res, get(id << 1, l, mid, pos));
        res = max(res, get(id << 1 | 1, mid + 1, r, pos));
        return res;
    }

    void update(int rem, ll val){
        int pos = lower_bound(vals.begin(), vals.end(), rem) - vals.begin() + 1;
        update(1, 1, n, 1, pos, val);
        update(1, 1, n, pos, n, val - a);
    }
    ll get(int rem){
        int pos = lower_bound(vals.begin(), vals.end(), rem) - vals.begin() + 1;
        return get(1, 1, n, pos);
    }
};

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> k >> m >> d >> a >> n;
    for(int i = 1; i <= n; i++)
        cin >> t[i].first >> t[i].second;
    m -= k;
    for(int i = 1; i <= n; i++)
        t[i].first -= k;
    k = 0;

    sort(t + 1, t + 1 + n);
    vector <int> vals;
    for(int i = 1; i <= n; i++)
        vals.push_back(t[i].first % d);
    vals.push_back(k % d);
    vals.push_back(m % d);
    sort(vals.begin(), vals.end());
    vals.resize(unique(vals.begin(), vals.end()) - vals.begin());

    segTree ST(vals, a);
    ST.update(k % d, 0);
    for(int i = 1; i <= n; i++){
        int rem = t[i].first % d;
        ll val = ST.get(rem) + t[i].second;
        ST.update(rem, val);
    }
    ll ans = ST.get(m % d) - m / d * a;
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 1776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 141 ms 3820 KB Output isn't correct
2 Halted 0 ms 0 KB -