Submission #967874

# Submission time Handle Problem Language Result Execution time Memory
967874 2024-04-23T03:34:41 Z Mike_Vu Long Distance Coach (JOI17_coach) C++14
100 / 100
245 ms 23892 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dou;
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second

//const ll mod = 1e9+7;

bool maximize(ll &x, ll y ){
    if (x < y) {x = y; return true;};
    return false;
}
bool minimize(ll &x, ll y){
    if (x > y) {x = y; return true;}
    return false;
}
//void add(ll &x, ll y ){
//    x += y;
//    if (x >= mod) x -= mod;
//}
//void sub(ll &x, ll y) {
//    x -= y;
//    if (x < 0) x += mod;
//}

struct Line{
    ll m, b;
    Line(ll slope = 0, ll intercept = 1e18+7){
        m = slope;
        b = intercept;
    }
    ll operator () (ll x){return m*x+b;}
};

struct LICHAO{
    vector<Line> tr;
    int trsz;
    LICHAO(int n = 0) {
        trsz = 1;
        while (trsz <= n) {
            trsz *= 2;
        }
        tr.assign(trsz*2, Line());
    }
    void update(Line a, int l, int r, int id){
        if (l + 1 == r) {
            if (tr[id](l) > a(l)) tr[id] = a;
            return;
        }
        int mid = (l+r) >> 1;
        if (tr[id].m < a.m) swap(tr[id], a);
        if (tr[id](mid) > a(mid)) {
            swap(tr[id], a);
            update(a, l, mid, id*2);
        }
        else {
            update(a, mid+1, r, id*2+1);
        }
    }
    ll query(ll x, int l, int r, int id) {
        if (l+1 == r) {
            return tr[id](x);
        }
        int mid = (l+r) >> 1;
        ll res = tr[id](x);
        if (x <= mid) return min(res, query(x, l, mid, id*2));
        else return min(res, query(x, mid+1, r, id*2+1));
    }
} cht;

const int maxn = 2e5+5;
int n, m;
ll x, lapse, w;
ll refill[maxn], a[maxn], b[maxn], dp[maxn], ps[maxn];
pii temp[maxn];

bool cmp1(ll a, ll b) {
    if ((a%lapse) != (b%lapse)) return (a%lapse) < (b%lapse);
    else return (a<b);
}
bool cmp2(pii a, pii b){
    return (a.fi <= b.fi);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> x >> n >> m >> w >> lapse;
    for (int i = 1; i <= n; i++) {
        cin >> refill[i];
    }
    ps[0] = 0;
    for (int i = 1; i <= m; i++) {
        cin >> temp[i].fi >> temp[i].se;
    }
    sort(temp+1, temp+m+1, cmp2);
    for (int i = 1; i <= m; i++) {
        a[i] = temp[i].fi;
        b[i] = temp[i].se;
        ps[i] = ps[i-1] + b[i];
    }
    refill[++n] = x;
    sort(refill+1, refill+n+1, cmp1);
    int j = n+1;
    dp[m+1] = 0;
    cht = LICHAO(m);
    for (int i = m; i > 0; i--){
        dp[i] = dp[i+1] + w*((x-a[i])/lapse+1);
//        system("pause");
        while (j-1 > 0 && (refill[j-1]%lapse) > a[i]) {
            --j;
            cht.update(Line(-w*(refill[j]/lapse), w*(refill[j]/lapse)*(i+1)+ps[i]+dp[i+1]),1,cht.trsz,1);
        }
//        system("pause");
        minimize(dp[i], cht.query(i, 1,cht.trsz,1)-ps[i-1]);
//        cout << dp[i] << ' ';
    }
    cout << dp[1]+(x/lapse+1)*w; //driver
}
/*
19 1 4 8 7
10
1 20
2 10
4 5
6 5

105 3 5 9 10
59
68
71
4 71
6 32
7 29
3 62
2 35
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8536 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 3 ms 8660 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8536 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8536 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 3 ms 8660 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8536 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 1 ms 8536 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 1 ms 8792 KB Output is correct
30 Correct 2 ms 8540 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 1 ms 8668 KB Output is correct
33 Correct 2 ms 8540 KB Output is correct
34 Correct 1 ms 8540 KB Output is correct
35 Correct 2 ms 8652 KB Output is correct
36 Correct 1 ms 8540 KB Output is correct
37 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8536 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 3 ms 8660 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8536 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 1 ms 8536 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 1 ms 8792 KB Output is correct
30 Correct 2 ms 8540 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 1 ms 8668 KB Output is correct
33 Correct 2 ms 8540 KB Output is correct
34 Correct 1 ms 8540 KB Output is correct
35 Correct 2 ms 8652 KB Output is correct
36 Correct 1 ms 8540 KB Output is correct
37 Correct 2 ms 8540 KB Output is correct
38 Correct 3 ms 8796 KB Output is correct
39 Correct 2 ms 8672 KB Output is correct
40 Correct 3 ms 8792 KB Output is correct
41 Correct 2 ms 8792 KB Output is correct
42 Correct 2 ms 8540 KB Output is correct
43 Correct 2 ms 8796 KB Output is correct
44 Correct 3 ms 8652 KB Output is correct
45 Correct 3 ms 8796 KB Output is correct
46 Correct 3 ms 8540 KB Output is correct
47 Correct 3 ms 8796 KB Output is correct
48 Correct 3 ms 8796 KB Output is correct
49 Correct 2 ms 8796 KB Output is correct
50 Correct 2 ms 8540 KB Output is correct
51 Correct 3 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8536 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 3 ms 8660 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8536 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 1 ms 8536 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 1 ms 8792 KB Output is correct
30 Correct 2 ms 8540 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 1 ms 8668 KB Output is correct
33 Correct 2 ms 8540 KB Output is correct
34 Correct 1 ms 8540 KB Output is correct
35 Correct 2 ms 8652 KB Output is correct
36 Correct 1 ms 8540 KB Output is correct
37 Correct 2 ms 8540 KB Output is correct
38 Correct 3 ms 8796 KB Output is correct
39 Correct 2 ms 8672 KB Output is correct
40 Correct 3 ms 8792 KB Output is correct
41 Correct 2 ms 8792 KB Output is correct
42 Correct 2 ms 8540 KB Output is correct
43 Correct 2 ms 8796 KB Output is correct
44 Correct 3 ms 8652 KB Output is correct
45 Correct 3 ms 8796 KB Output is correct
46 Correct 3 ms 8540 KB Output is correct
47 Correct 3 ms 8796 KB Output is correct
48 Correct 3 ms 8796 KB Output is correct
49 Correct 2 ms 8796 KB Output is correct
50 Correct 2 ms 8540 KB Output is correct
51 Correct 3 ms 8540 KB Output is correct
52 Correct 167 ms 23636 KB Output is correct
53 Correct 196 ms 23676 KB Output is correct
54 Correct 161 ms 22916 KB Output is correct
55 Correct 156 ms 23124 KB Output is correct
56 Correct 160 ms 23380 KB Output is correct
57 Correct 168 ms 23180 KB Output is correct
58 Correct 159 ms 23740 KB Output is correct
59 Correct 158 ms 23112 KB Output is correct
60 Correct 156 ms 22912 KB Output is correct
61 Correct 159 ms 23100 KB Output is correct
62 Correct 165 ms 23120 KB Output is correct
63 Correct 186 ms 22100 KB Output is correct
64 Correct 134 ms 23892 KB Output is correct
65 Correct 241 ms 23632 KB Output is correct
66 Correct 242 ms 23792 KB Output is correct
67 Correct 245 ms 23788 KB Output is correct
68 Correct 242 ms 23788 KB Output is correct
69 Correct 169 ms 23636 KB Output is correct
70 Correct 164 ms 23376 KB Output is correct
71 Correct 166 ms 23440 KB Output is correct
72 Correct 168 ms 23392 KB Output is correct
73 Correct 165 ms 23540 KB Output is correct
74 Correct 168 ms 23588 KB Output is correct
75 Correct 170 ms 23680 KB Output is correct
76 Correct 163 ms 23636 KB Output is correct
77 Correct 172 ms 23280 KB Output is correct
78 Correct 161 ms 23652 KB Output is correct
79 Correct 172 ms 23252 KB Output is correct
80 Correct 163 ms 23128 KB Output is correct