Submission #892767

# Submission time Handle Problem Language Result Execution time Memory
892767 2023-12-25T22:42:14 Z ksujay2 Long Distance Coach (JOI17_coach) C++17
100 / 100
226 ms 17108 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct Line {
	mutable ll k, m, p;
	bool operator<(const Line& o) const { return k < o.k; }
	bool operator<(ll x) const { return p < x; }
};

struct LineContainer : multiset<Line, less<>> {
	static const ll inf = LLONG_MAX;
	ll div(ll a, ll b) {
		return a / b - ((a ^ b) < 0 && a % b); }
	bool isect(iterator x, iterator y) {
		if (y == end()) return x->p = inf, 0;
		if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
		else x->p = div(y->m - x->m, x->k - y->k);
		return x->p >= y->p;
	}
	void add(ll k, ll m) {
		auto z = insert({k, m, 0}), y = z++, x = y;
		while (isect(y, z)) z = erase(z);
		if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
		while ((y = x) != begin() && (--x)->p >= y->p)
			isect(x, erase(y));
	}
	ll query(ll x) {
		assert(!empty());
		auto l = *lower_bound(x);
		return l.k * x + l.m;
	}
};

int main() {
    ll X, N, M, W, T;
    cin >> X >> N >> M >> W >> T;
    vector<pair<ll, ll>> e;
    for(int i = 0; i < N; i++) {
        ll s; cin >> s;
        e.push_back({s % T, -s});
    }
    e.push_back({X % T, -X});
    ll mndp = (X / T + 1) * W;
    for(int i = 0; i < M; i++) {
        ll d, c; cin >> d >> c;
        mndp += ((X - d) / T + 1) * W;
        e.push_back({d, c});
    }
    sort(e.begin(), e.end());
    ll g = 0;
    ll x = 0;
    LineContainer lc;
    for(int i = e.size() - 1; i >= 0; i--) {
        if(e[i].second < 0) {
            ll m = W * (-e[i].second / T);
            lc.add(-m, -(mndp - g - x * m));
        } else {
            if(!lc.empty()) {
                g += e[i].second - ((X - e[i].first) / T + 1) * W;
                x++;
                mndp = min(mndp, g - lc.query(x));
            }
        }
    }
    cout << mndp << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 440 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 388 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 432 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 440 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 388 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 432 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 432 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 500 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 440 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 388 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 432 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 432 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 500 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 348 KB Output is correct
42 Correct 2 ms 444 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 2 ms 420 KB Output is correct
46 Correct 2 ms 344 KB Output is correct
47 Correct 2 ms 600 KB Output is correct
48 Correct 2 ms 536 KB Output is correct
49 Correct 2 ms 608 KB Output is correct
50 Correct 2 ms 348 KB Output is correct
51 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 440 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 388 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 432 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 432 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 500 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 348 KB Output is correct
42 Correct 2 ms 444 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 2 ms 420 KB Output is correct
46 Correct 2 ms 344 KB Output is correct
47 Correct 2 ms 600 KB Output is correct
48 Correct 2 ms 536 KB Output is correct
49 Correct 2 ms 608 KB Output is correct
50 Correct 2 ms 348 KB Output is correct
51 Correct 2 ms 604 KB Output is correct
52 Correct 210 ms 13904 KB Output is correct
53 Correct 209 ms 12984 KB Output is correct
54 Correct 190 ms 13748 KB Output is correct
55 Correct 195 ms 13524 KB Output is correct
56 Correct 202 ms 13752 KB Output is correct
57 Correct 200 ms 13660 KB Output is correct
58 Correct 207 ms 14268 KB Output is correct
59 Correct 196 ms 14008 KB Output is correct
60 Correct 190 ms 12468 KB Output is correct
61 Correct 196 ms 12724 KB Output is correct
62 Correct 196 ms 12468 KB Output is correct
63 Correct 221 ms 17108 KB Output is correct
64 Correct 179 ms 13256 KB Output is correct
65 Correct 217 ms 13240 KB Output is correct
66 Correct 218 ms 13668 KB Output is correct
67 Correct 207 ms 14264 KB Output is correct
68 Correct 206 ms 12980 KB Output is correct
69 Correct 212 ms 14268 KB Output is correct
70 Correct 207 ms 14132 KB Output is correct
71 Correct 208 ms 14008 KB Output is correct
72 Correct 213 ms 12828 KB Output is correct
73 Correct 224 ms 12612 KB Output is correct
74 Correct 226 ms 13052 KB Output is correct
75 Correct 214 ms 13228 KB Output is correct
76 Correct 216 ms 12472 KB Output is correct
77 Correct 203 ms 12804 KB Output is correct
78 Correct 202 ms 14168 KB Output is correct
79 Correct 200 ms 12196 KB Output is correct
80 Correct 198 ms 12924 KB Output is correct