#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int INF = (int) 1e9 + 1e6;
const ll LINF = (ll) 1e18 + 1e9;
const ll MOD = (ll) 1e9 + 7;
#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (auto i = f; i < t; ++(i))
#define per(i, f, t) for (auto i = (f); i >= (t); --(i))
ll power(ll x, ll y, ll mod = MOD) {
if (y == 0) {
return 1;
}
if (y & 1) {
return power(x, y - 1, mod) * x % mod;
} else {
ll tmp = power(x, y / 2, mod);
return tmp * tmp % mod;
}
}
template<typename A, typename B> bool mini(A &x, const B &y) {
if (y < x) {
x = y;
return true;
}
return false;
}
template<typename A, typename B> bool maxi(A &x, const B &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
void add(ll &x, ll y) {
x += y;
if (x >= MOD) x -= MOD;
if (x < 0) x += MOD;
}
void run();
#define TASK ""
int main() {
#ifdef LOCAL
if (strlen(TASK) > 0) {
cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
}
#endif
#ifndef LOCAL
if (strlen(TASK)) {
freopen(TASK ".in", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#endif
cout << fixed << setprecision(12);
run();
return 0;
}
// == SOLUTION == //
const int N = (int) 2e5 + 123;
int n, m;
ll x, w, t;
ll s[N];
pair<ll, ll> p[N];
ll d[N], c[N];
int r[N];
vector<int> what[N];
ll dp[N];
struct Line {
ll k, b;
ll val(ll x) const {
return k * x + b;
}
};
ll div_up(ll x, ll y) {
if (y < 0) {
x = -x;
y = -y;
}
if (x < 0) {
return x / y;
} else {
return (x + y - 1) / y;
}
}
ll inter(const Line &a, const Line &b) {
return div_up(b.b - a.b, a.k - b.k);
}
struct CHT {
vector<Line> lines;
vector<ll> points;
void add(const Line &l) {
while (sz(points) && inter(l, lines.back()) <= points.back()) {
points.pop_back();
lines.pop_back();
}
if (sz(lines)) {
points.pb(inter(l, lines.back()));
}
lines.pb(l);
}
ll get(ll x) {
int pos = (int) (upper_bound(all(points), x) - points.begin());
return lines[pos].val(x);
}
};
CHT cht;
void run() {
cin >> x >> n >> m >> w >> t;
rep(i, 1, n + 1) {
cin >> s[i];
}
s[n + 1] = x;
rep(i, 1, m + 1) {
cin >> p[i].first >> p[i].second;
}
sort(p + 1, p + m + 1);
rep(i, 1, m + 1) {
d[i] = p[i].first;
c[i] = p[i].second;
}
rep(i, 0, n + 1) {
r[i] = (int) (lower_bound(d, d + m + 1, s[i + 1] % t) - d) - 1;
what[r[i]].pb(i);
}
dp[0] = s[n + 1] / t * w + w;
cht.add({0, dp[0]});
ll fee = 0;
rep(i, 1, m + 1) {
fee += c[i];
dp[i] = dp[i - 1] + (s[n + 1] - d[i]) / t * w + w;
for (int id : what[i]) {
ll cnt = s[id + 1] / t;
mini(dp[i], cht.get(cnt * w) + fee + i * cnt * w);
}
cht.add({-i, dp[i] - fee});
}
cout << dp[m] << "\n";
}
Compilation message
coach.cpp: In function 'int main()':
coach.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(TASK ".in", "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(TASK ".out", "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5112 KB |
Output is correct |
2 |
Correct |
5 ms |
5112 KB |
Output is correct |
3 |
Correct |
5 ms |
5164 KB |
Output is correct |
4 |
Correct |
5 ms |
5240 KB |
Output is correct |
5 |
Correct |
5 ms |
5300 KB |
Output is correct |
6 |
Correct |
5 ms |
5300 KB |
Output is correct |
7 |
Correct |
5 ms |
5300 KB |
Output is correct |
8 |
Correct |
5 ms |
5356 KB |
Output is correct |
9 |
Correct |
5 ms |
5356 KB |
Output is correct |
10 |
Correct |
5 ms |
5464 KB |
Output is correct |
11 |
Correct |
5 ms |
5468 KB |
Output is correct |
12 |
Correct |
5 ms |
5468 KB |
Output is correct |
13 |
Correct |
5 ms |
5468 KB |
Output is correct |
14 |
Correct |
5 ms |
5468 KB |
Output is correct |
15 |
Correct |
5 ms |
5468 KB |
Output is correct |
16 |
Correct |
5 ms |
5468 KB |
Output is correct |
17 |
Correct |
5 ms |
5468 KB |
Output is correct |
18 |
Correct |
5 ms |
5468 KB |
Output is correct |
19 |
Correct |
5 ms |
5484 KB |
Output is correct |
20 |
Correct |
5 ms |
5484 KB |
Output is correct |
21 |
Correct |
5 ms |
5484 KB |
Output is correct |
22 |
Correct |
5 ms |
5484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5112 KB |
Output is correct |
2 |
Correct |
5 ms |
5112 KB |
Output is correct |
3 |
Correct |
5 ms |
5164 KB |
Output is correct |
4 |
Correct |
5 ms |
5240 KB |
Output is correct |
5 |
Correct |
5 ms |
5300 KB |
Output is correct |
6 |
Correct |
5 ms |
5300 KB |
Output is correct |
7 |
Correct |
5 ms |
5300 KB |
Output is correct |
8 |
Correct |
5 ms |
5356 KB |
Output is correct |
9 |
Correct |
5 ms |
5356 KB |
Output is correct |
10 |
Correct |
5 ms |
5464 KB |
Output is correct |
11 |
Correct |
5 ms |
5468 KB |
Output is correct |
12 |
Correct |
5 ms |
5468 KB |
Output is correct |
13 |
Correct |
5 ms |
5468 KB |
Output is correct |
14 |
Correct |
5 ms |
5468 KB |
Output is correct |
15 |
Correct |
5 ms |
5468 KB |
Output is correct |
16 |
Correct |
5 ms |
5468 KB |
Output is correct |
17 |
Correct |
5 ms |
5468 KB |
Output is correct |
18 |
Correct |
5 ms |
5468 KB |
Output is correct |
19 |
Correct |
5 ms |
5484 KB |
Output is correct |
20 |
Correct |
5 ms |
5484 KB |
Output is correct |
21 |
Correct |
5 ms |
5484 KB |
Output is correct |
22 |
Correct |
5 ms |
5484 KB |
Output is correct |
23 |
Correct |
5 ms |
5484 KB |
Output is correct |
24 |
Correct |
5 ms |
5484 KB |
Output is correct |
25 |
Correct |
5 ms |
5484 KB |
Output is correct |
26 |
Correct |
5 ms |
5484 KB |
Output is correct |
27 |
Correct |
5 ms |
5484 KB |
Output is correct |
28 |
Correct |
5 ms |
5484 KB |
Output is correct |
29 |
Correct |
5 ms |
5484 KB |
Output is correct |
30 |
Correct |
5 ms |
5484 KB |
Output is correct |
31 |
Correct |
5 ms |
5484 KB |
Output is correct |
32 |
Correct |
5 ms |
5484 KB |
Output is correct |
33 |
Correct |
5 ms |
5484 KB |
Output is correct |
34 |
Correct |
5 ms |
5484 KB |
Output is correct |
35 |
Correct |
5 ms |
5484 KB |
Output is correct |
36 |
Correct |
7 ms |
5484 KB |
Output is correct |
37 |
Correct |
5 ms |
5484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5112 KB |
Output is correct |
2 |
Correct |
5 ms |
5112 KB |
Output is correct |
3 |
Correct |
5 ms |
5164 KB |
Output is correct |
4 |
Correct |
5 ms |
5240 KB |
Output is correct |
5 |
Correct |
5 ms |
5300 KB |
Output is correct |
6 |
Correct |
5 ms |
5300 KB |
Output is correct |
7 |
Correct |
5 ms |
5300 KB |
Output is correct |
8 |
Correct |
5 ms |
5356 KB |
Output is correct |
9 |
Correct |
5 ms |
5356 KB |
Output is correct |
10 |
Correct |
5 ms |
5464 KB |
Output is correct |
11 |
Correct |
5 ms |
5468 KB |
Output is correct |
12 |
Correct |
5 ms |
5468 KB |
Output is correct |
13 |
Correct |
5 ms |
5468 KB |
Output is correct |
14 |
Correct |
5 ms |
5468 KB |
Output is correct |
15 |
Correct |
5 ms |
5468 KB |
Output is correct |
16 |
Correct |
5 ms |
5468 KB |
Output is correct |
17 |
Correct |
5 ms |
5468 KB |
Output is correct |
18 |
Correct |
5 ms |
5468 KB |
Output is correct |
19 |
Correct |
5 ms |
5484 KB |
Output is correct |
20 |
Correct |
5 ms |
5484 KB |
Output is correct |
21 |
Correct |
5 ms |
5484 KB |
Output is correct |
22 |
Correct |
5 ms |
5484 KB |
Output is correct |
23 |
Correct |
5 ms |
5484 KB |
Output is correct |
24 |
Correct |
5 ms |
5484 KB |
Output is correct |
25 |
Correct |
5 ms |
5484 KB |
Output is correct |
26 |
Correct |
5 ms |
5484 KB |
Output is correct |
27 |
Correct |
5 ms |
5484 KB |
Output is correct |
28 |
Correct |
5 ms |
5484 KB |
Output is correct |
29 |
Correct |
5 ms |
5484 KB |
Output is correct |
30 |
Correct |
5 ms |
5484 KB |
Output is correct |
31 |
Correct |
5 ms |
5484 KB |
Output is correct |
32 |
Correct |
5 ms |
5484 KB |
Output is correct |
33 |
Correct |
5 ms |
5484 KB |
Output is correct |
34 |
Correct |
5 ms |
5484 KB |
Output is correct |
35 |
Correct |
5 ms |
5484 KB |
Output is correct |
36 |
Correct |
7 ms |
5484 KB |
Output is correct |
37 |
Correct |
5 ms |
5484 KB |
Output is correct |
38 |
Correct |
6 ms |
5500 KB |
Output is correct |
39 |
Correct |
6 ms |
5500 KB |
Output is correct |
40 |
Correct |
7 ms |
5500 KB |
Output is correct |
41 |
Correct |
6 ms |
5500 KB |
Output is correct |
42 |
Correct |
7 ms |
5500 KB |
Output is correct |
43 |
Correct |
6 ms |
5504 KB |
Output is correct |
44 |
Correct |
6 ms |
5504 KB |
Output is correct |
45 |
Correct |
6 ms |
5504 KB |
Output is correct |
46 |
Correct |
6 ms |
5584 KB |
Output is correct |
47 |
Correct |
6 ms |
5592 KB |
Output is correct |
48 |
Correct |
7 ms |
5592 KB |
Output is correct |
49 |
Correct |
7 ms |
5592 KB |
Output is correct |
50 |
Correct |
6 ms |
5592 KB |
Output is correct |
51 |
Correct |
7 ms |
5592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5112 KB |
Output is correct |
2 |
Correct |
5 ms |
5112 KB |
Output is correct |
3 |
Correct |
5 ms |
5164 KB |
Output is correct |
4 |
Correct |
5 ms |
5240 KB |
Output is correct |
5 |
Correct |
5 ms |
5300 KB |
Output is correct |
6 |
Correct |
5 ms |
5300 KB |
Output is correct |
7 |
Correct |
5 ms |
5300 KB |
Output is correct |
8 |
Correct |
5 ms |
5356 KB |
Output is correct |
9 |
Correct |
5 ms |
5356 KB |
Output is correct |
10 |
Correct |
5 ms |
5464 KB |
Output is correct |
11 |
Correct |
5 ms |
5468 KB |
Output is correct |
12 |
Correct |
5 ms |
5468 KB |
Output is correct |
13 |
Correct |
5 ms |
5468 KB |
Output is correct |
14 |
Correct |
5 ms |
5468 KB |
Output is correct |
15 |
Correct |
5 ms |
5468 KB |
Output is correct |
16 |
Correct |
5 ms |
5468 KB |
Output is correct |
17 |
Correct |
5 ms |
5468 KB |
Output is correct |
18 |
Correct |
5 ms |
5468 KB |
Output is correct |
19 |
Correct |
5 ms |
5484 KB |
Output is correct |
20 |
Correct |
5 ms |
5484 KB |
Output is correct |
21 |
Correct |
5 ms |
5484 KB |
Output is correct |
22 |
Correct |
5 ms |
5484 KB |
Output is correct |
23 |
Correct |
5 ms |
5484 KB |
Output is correct |
24 |
Correct |
5 ms |
5484 KB |
Output is correct |
25 |
Correct |
5 ms |
5484 KB |
Output is correct |
26 |
Correct |
5 ms |
5484 KB |
Output is correct |
27 |
Correct |
5 ms |
5484 KB |
Output is correct |
28 |
Correct |
5 ms |
5484 KB |
Output is correct |
29 |
Correct |
5 ms |
5484 KB |
Output is correct |
30 |
Correct |
5 ms |
5484 KB |
Output is correct |
31 |
Correct |
5 ms |
5484 KB |
Output is correct |
32 |
Correct |
5 ms |
5484 KB |
Output is correct |
33 |
Correct |
5 ms |
5484 KB |
Output is correct |
34 |
Correct |
5 ms |
5484 KB |
Output is correct |
35 |
Correct |
5 ms |
5484 KB |
Output is correct |
36 |
Correct |
7 ms |
5484 KB |
Output is correct |
37 |
Correct |
5 ms |
5484 KB |
Output is correct |
38 |
Correct |
6 ms |
5500 KB |
Output is correct |
39 |
Correct |
6 ms |
5500 KB |
Output is correct |
40 |
Correct |
7 ms |
5500 KB |
Output is correct |
41 |
Correct |
6 ms |
5500 KB |
Output is correct |
42 |
Correct |
7 ms |
5500 KB |
Output is correct |
43 |
Correct |
6 ms |
5504 KB |
Output is correct |
44 |
Correct |
6 ms |
5504 KB |
Output is correct |
45 |
Correct |
6 ms |
5504 KB |
Output is correct |
46 |
Correct |
6 ms |
5584 KB |
Output is correct |
47 |
Correct |
6 ms |
5592 KB |
Output is correct |
48 |
Correct |
7 ms |
5592 KB |
Output is correct |
49 |
Correct |
7 ms |
5592 KB |
Output is correct |
50 |
Correct |
6 ms |
5592 KB |
Output is correct |
51 |
Correct |
7 ms |
5592 KB |
Output is correct |
52 |
Correct |
219 ms |
18684 KB |
Output is correct |
53 |
Correct |
181 ms |
27604 KB |
Output is correct |
54 |
Correct |
207 ms |
29492 KB |
Output is correct |
55 |
Correct |
221 ms |
34660 KB |
Output is correct |
56 |
Correct |
209 ms |
39904 KB |
Output is correct |
57 |
Correct |
220 ms |
45260 KB |
Output is correct |
58 |
Correct |
212 ms |
51016 KB |
Output is correct |
59 |
Correct |
215 ms |
56084 KB |
Output is correct |
60 |
Correct |
225 ms |
61088 KB |
Output is correct |
61 |
Correct |
224 ms |
66200 KB |
Output is correct |
62 |
Correct |
234 ms |
71352 KB |
Output is correct |
63 |
Correct |
127 ms |
85120 KB |
Output is correct |
64 |
Correct |
120 ms |
85120 KB |
Output is correct |
65 |
Correct |
146 ms |
89808 KB |
Output is correct |
66 |
Correct |
138 ms |
95604 KB |
Output is correct |
67 |
Correct |
144 ms |
101372 KB |
Output is correct |
68 |
Correct |
142 ms |
107088 KB |
Output is correct |
69 |
Correct |
226 ms |
109776 KB |
Output is correct |
70 |
Correct |
237 ms |
115080 KB |
Output is correct |
71 |
Correct |
222 ms |
120576 KB |
Output is correct |
72 |
Correct |
223 ms |
126200 KB |
Output is correct |
73 |
Correct |
218 ms |
131576 KB |
Output is correct |
74 |
Correct |
213 ms |
137212 KB |
Output is correct |
75 |
Correct |
226 ms |
142784 KB |
Output is correct |
76 |
Correct |
256 ms |
148556 KB |
Output is correct |
77 |
Correct |
204 ms |
153892 KB |
Output is correct |
78 |
Correct |
251 ms |
159712 KB |
Output is correct |
79 |
Correct |
218 ms |
164856 KB |
Output is correct |
80 |
Correct |
207 ms |
169844 KB |
Output is correct |