#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
int q, n;
ll x, t, w;
lll dp[200010], m[200010], k[200010], d[200010], c[200010];
pll a[200010], b[200010];
struct CHT{
struct Lin{ lll a, b; };
ld cr(Lin p, Lin q){ return ld(q.b - p.b) / ld(p.a - q.a); }
vector<Lin> v;
int r;
void upd(lll a, lll b){
Lin c = {a, b};
while(r > 1 && cr(v[r - 2], v[r - 1]) > cr(v[r - 2], c)){ v.pop_back(); r--; }
v.push_back(c); r++;
}
lll get(lll x){
int s = 0, e = r - 2;
while(s <= e){
int m = (s + e) / 2;
if(cr(v[m], v[m + 1]) <= x) s = m + 1;
else e = m - 1;
}
return v[s].a * x + v[s].b;
}
} C;
int main(){
scanf("%lld%d%d%lld%lld", &x, &q, &n, &w, &t);
b[0] = {x % t, x / t};
for(int i = 1; i <= q; i++){
ll x; scanf("%lld", &x);
b[i] = {x % t, x / t};
}
for(int i = 1; i <= n; i++){
scanf("%lld%lld", &a[i].first, &a[i].second);
}
sort(a + 1, a + n + 1);
k[0] = (x + t - 1) / t;
for(int i = 1; i <= n; i++){
c[i] = c[i - 1] + a[i].second;
k[i] = k[i - 1] + x / t + (a[i].first < x % t);
}
fill(m + 1, m + n + 1, (x + t - 1) / t + 1);
for(int i = 0; i <= q; i++){
int t = int(upper_bound(a + 1, a + n + 1, b[i]) - a - 1);
m[t] = min(m[t], lll(b[i].second));
}
C.upd(0, -k[0] * w);
for(int i = 1; i <= n; i++){
dp[i] = max(dp[i - 1], C.get(m[i]) + (k[i] - i * m[i]) * w - c[i]);
C.upd(i * w, dp[i] + c[i] - k[i] * w);
}
printf("%lld\n", ll(k[n] * w - dp[n]));
}
Compilation message
coach.cpp: In function 'int main()':
coach.cpp:35:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%d%d%lld%lld", &x, &q, &n, &w, &t);
^
coach.cpp:38:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
ll x; scanf("%lld", &x);
^
coach.cpp:42:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &a[i].first, &a[i].second);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
23900 KB |
Output is correct |
2 |
Correct |
0 ms |
23900 KB |
Output is correct |
3 |
Correct |
0 ms |
23900 KB |
Output is correct |
4 |
Correct |
0 ms |
23900 KB |
Output is correct |
5 |
Correct |
0 ms |
23900 KB |
Output is correct |
6 |
Correct |
0 ms |
23900 KB |
Output is correct |
7 |
Correct |
0 ms |
23900 KB |
Output is correct |
8 |
Correct |
0 ms |
23900 KB |
Output is correct |
9 |
Correct |
0 ms |
23900 KB |
Output is correct |
10 |
Correct |
0 ms |
23900 KB |
Output is correct |
11 |
Correct |
0 ms |
23900 KB |
Output is correct |
12 |
Correct |
0 ms |
23900 KB |
Output is correct |
13 |
Correct |
0 ms |
23900 KB |
Output is correct |
14 |
Correct |
0 ms |
23900 KB |
Output is correct |
15 |
Correct |
0 ms |
23900 KB |
Output is correct |
16 |
Correct |
0 ms |
23900 KB |
Output is correct |
17 |
Correct |
0 ms |
23900 KB |
Output is correct |
18 |
Correct |
0 ms |
23900 KB |
Output is correct |
19 |
Correct |
0 ms |
23900 KB |
Output is correct |
20 |
Correct |
0 ms |
23900 KB |
Output is correct |
21 |
Correct |
0 ms |
23900 KB |
Output is correct |
22 |
Correct |
0 ms |
23900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
23900 KB |
Output is correct |
2 |
Correct |
0 ms |
23900 KB |
Output is correct |
3 |
Correct |
0 ms |
23900 KB |
Output is correct |
4 |
Correct |
0 ms |
23900 KB |
Output is correct |
5 |
Correct |
0 ms |
23900 KB |
Output is correct |
6 |
Correct |
0 ms |
23900 KB |
Output is correct |
7 |
Correct |
0 ms |
23900 KB |
Output is correct |
8 |
Correct |
0 ms |
23900 KB |
Output is correct |
9 |
Correct |
0 ms |
23900 KB |
Output is correct |
10 |
Correct |
0 ms |
23900 KB |
Output is correct |
11 |
Correct |
0 ms |
23900 KB |
Output is correct |
12 |
Correct |
0 ms |
23900 KB |
Output is correct |
13 |
Correct |
0 ms |
23900 KB |
Output is correct |
14 |
Correct |
0 ms |
23900 KB |
Output is correct |
15 |
Correct |
0 ms |
23900 KB |
Output is correct |
16 |
Correct |
0 ms |
23900 KB |
Output is correct |
17 |
Correct |
0 ms |
23900 KB |
Output is correct |
18 |
Correct |
0 ms |
23900 KB |
Output is correct |
19 |
Correct |
0 ms |
23900 KB |
Output is correct |
20 |
Correct |
0 ms |
23900 KB |
Output is correct |
21 |
Correct |
0 ms |
23900 KB |
Output is correct |
22 |
Correct |
0 ms |
23900 KB |
Output is correct |
23 |
Correct |
0 ms |
23900 KB |
Output is correct |
24 |
Correct |
0 ms |
23900 KB |
Output is correct |
25 |
Correct |
0 ms |
23900 KB |
Output is correct |
26 |
Correct |
0 ms |
23900 KB |
Output is correct |
27 |
Correct |
0 ms |
23900 KB |
Output is correct |
28 |
Correct |
0 ms |
23900 KB |
Output is correct |
29 |
Correct |
0 ms |
23900 KB |
Output is correct |
30 |
Correct |
0 ms |
23900 KB |
Output is correct |
31 |
Correct |
0 ms |
23900 KB |
Output is correct |
32 |
Correct |
0 ms |
23900 KB |
Output is correct |
33 |
Correct |
0 ms |
23900 KB |
Output is correct |
34 |
Correct |
0 ms |
23900 KB |
Output is correct |
35 |
Correct |
0 ms |
23900 KB |
Output is correct |
36 |
Correct |
0 ms |
23900 KB |
Output is correct |
37 |
Correct |
0 ms |
23900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
23900 KB |
Output is correct |
2 |
Correct |
0 ms |
23900 KB |
Output is correct |
3 |
Correct |
0 ms |
23900 KB |
Output is correct |
4 |
Correct |
0 ms |
23900 KB |
Output is correct |
5 |
Correct |
0 ms |
23900 KB |
Output is correct |
6 |
Correct |
0 ms |
23900 KB |
Output is correct |
7 |
Correct |
0 ms |
23900 KB |
Output is correct |
8 |
Correct |
0 ms |
23900 KB |
Output is correct |
9 |
Correct |
0 ms |
23900 KB |
Output is correct |
10 |
Correct |
0 ms |
23900 KB |
Output is correct |
11 |
Correct |
0 ms |
23900 KB |
Output is correct |
12 |
Correct |
0 ms |
23900 KB |
Output is correct |
13 |
Correct |
0 ms |
23900 KB |
Output is correct |
14 |
Correct |
0 ms |
23900 KB |
Output is correct |
15 |
Correct |
0 ms |
23900 KB |
Output is correct |
16 |
Correct |
0 ms |
23900 KB |
Output is correct |
17 |
Correct |
0 ms |
23900 KB |
Output is correct |
18 |
Correct |
0 ms |
23900 KB |
Output is correct |
19 |
Correct |
0 ms |
23900 KB |
Output is correct |
20 |
Correct |
0 ms |
23900 KB |
Output is correct |
21 |
Correct |
0 ms |
23900 KB |
Output is correct |
22 |
Correct |
0 ms |
23900 KB |
Output is correct |
23 |
Correct |
0 ms |
23900 KB |
Output is correct |
24 |
Correct |
0 ms |
23900 KB |
Output is correct |
25 |
Correct |
0 ms |
23900 KB |
Output is correct |
26 |
Correct |
0 ms |
23900 KB |
Output is correct |
27 |
Correct |
0 ms |
23900 KB |
Output is correct |
28 |
Correct |
0 ms |
23900 KB |
Output is correct |
29 |
Correct |
0 ms |
23900 KB |
Output is correct |
30 |
Correct |
0 ms |
23900 KB |
Output is correct |
31 |
Correct |
0 ms |
23900 KB |
Output is correct |
32 |
Correct |
0 ms |
23900 KB |
Output is correct |
33 |
Correct |
0 ms |
23900 KB |
Output is correct |
34 |
Correct |
0 ms |
23900 KB |
Output is correct |
35 |
Correct |
0 ms |
23900 KB |
Output is correct |
36 |
Correct |
0 ms |
23900 KB |
Output is correct |
37 |
Correct |
0 ms |
23900 KB |
Output is correct |
38 |
Correct |
0 ms |
23900 KB |
Output is correct |
39 |
Correct |
0 ms |
23900 KB |
Output is correct |
40 |
Correct |
0 ms |
23900 KB |
Output is correct |
41 |
Correct |
0 ms |
24040 KB |
Output is correct |
42 |
Correct |
0 ms |
23900 KB |
Output is correct |
43 |
Correct |
0 ms |
23900 KB |
Output is correct |
44 |
Correct |
0 ms |
23900 KB |
Output is correct |
45 |
Correct |
0 ms |
23900 KB |
Output is correct |
46 |
Correct |
0 ms |
24040 KB |
Output is correct |
47 |
Correct |
0 ms |
23900 KB |
Output is correct |
48 |
Correct |
3 ms |
23900 KB |
Output is correct |
49 |
Correct |
0 ms |
24040 KB |
Output is correct |
50 |
Correct |
0 ms |
23900 KB |
Output is correct |
51 |
Correct |
0 ms |
23900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
23900 KB |
Output is correct |
2 |
Correct |
0 ms |
23900 KB |
Output is correct |
3 |
Correct |
0 ms |
23900 KB |
Output is correct |
4 |
Correct |
0 ms |
23900 KB |
Output is correct |
5 |
Correct |
0 ms |
23900 KB |
Output is correct |
6 |
Correct |
0 ms |
23900 KB |
Output is correct |
7 |
Correct |
0 ms |
23900 KB |
Output is correct |
8 |
Correct |
0 ms |
23900 KB |
Output is correct |
9 |
Correct |
0 ms |
23900 KB |
Output is correct |
10 |
Correct |
0 ms |
23900 KB |
Output is correct |
11 |
Correct |
0 ms |
23900 KB |
Output is correct |
12 |
Correct |
0 ms |
23900 KB |
Output is correct |
13 |
Correct |
0 ms |
23900 KB |
Output is correct |
14 |
Correct |
0 ms |
23900 KB |
Output is correct |
15 |
Correct |
0 ms |
23900 KB |
Output is correct |
16 |
Correct |
0 ms |
23900 KB |
Output is correct |
17 |
Correct |
0 ms |
23900 KB |
Output is correct |
18 |
Correct |
0 ms |
23900 KB |
Output is correct |
19 |
Correct |
0 ms |
23900 KB |
Output is correct |
20 |
Correct |
0 ms |
23900 KB |
Output is correct |
21 |
Correct |
0 ms |
23900 KB |
Output is correct |
22 |
Correct |
0 ms |
23900 KB |
Output is correct |
23 |
Correct |
0 ms |
23900 KB |
Output is correct |
24 |
Correct |
0 ms |
23900 KB |
Output is correct |
25 |
Correct |
0 ms |
23900 KB |
Output is correct |
26 |
Correct |
0 ms |
23900 KB |
Output is correct |
27 |
Correct |
0 ms |
23900 KB |
Output is correct |
28 |
Correct |
0 ms |
23900 KB |
Output is correct |
29 |
Correct |
0 ms |
23900 KB |
Output is correct |
30 |
Correct |
0 ms |
23900 KB |
Output is correct |
31 |
Correct |
0 ms |
23900 KB |
Output is correct |
32 |
Correct |
0 ms |
23900 KB |
Output is correct |
33 |
Correct |
0 ms |
23900 KB |
Output is correct |
34 |
Correct |
0 ms |
23900 KB |
Output is correct |
35 |
Correct |
0 ms |
23900 KB |
Output is correct |
36 |
Correct |
0 ms |
23900 KB |
Output is correct |
37 |
Correct |
0 ms |
23900 KB |
Output is correct |
38 |
Correct |
0 ms |
23900 KB |
Output is correct |
39 |
Correct |
0 ms |
23900 KB |
Output is correct |
40 |
Correct |
0 ms |
23900 KB |
Output is correct |
41 |
Correct |
0 ms |
24040 KB |
Output is correct |
42 |
Correct |
0 ms |
23900 KB |
Output is correct |
43 |
Correct |
0 ms |
23900 KB |
Output is correct |
44 |
Correct |
0 ms |
23900 KB |
Output is correct |
45 |
Correct |
0 ms |
23900 KB |
Output is correct |
46 |
Correct |
0 ms |
24040 KB |
Output is correct |
47 |
Correct |
0 ms |
23900 KB |
Output is correct |
48 |
Correct |
3 ms |
23900 KB |
Output is correct |
49 |
Correct |
0 ms |
24040 KB |
Output is correct |
50 |
Correct |
0 ms |
23900 KB |
Output is correct |
51 |
Correct |
0 ms |
23900 KB |
Output is correct |
52 |
Correct |
219 ms |
23900 KB |
Output is correct |
53 |
Correct |
149 ms |
23900 KB |
Output is correct |
54 |
Correct |
206 ms |
27056 KB |
Output is correct |
55 |
Correct |
189 ms |
25520 KB |
Output is correct |
56 |
Correct |
206 ms |
24172 KB |
Output is correct |
57 |
Correct |
209 ms |
24172 KB |
Output is correct |
58 |
Correct |
233 ms |
23900 KB |
Output is correct |
59 |
Correct |
206 ms |
25520 KB |
Output is correct |
60 |
Correct |
209 ms |
24752 KB |
Output is correct |
61 |
Correct |
176 ms |
25520 KB |
Output is correct |
62 |
Correct |
189 ms |
24752 KB |
Output is correct |
63 |
Correct |
163 ms |
36272 KB |
Output is correct |
64 |
Correct |
159 ms |
23900 KB |
Output is correct |
65 |
Correct |
146 ms |
23900 KB |
Output is correct |
66 |
Correct |
136 ms |
23900 KB |
Output is correct |
67 |
Correct |
159 ms |
23900 KB |
Output is correct |
68 |
Correct |
179 ms |
23900 KB |
Output is correct |
69 |
Correct |
209 ms |
23900 KB |
Output is correct |
70 |
Correct |
193 ms |
23900 KB |
Output is correct |
71 |
Correct |
226 ms |
23900 KB |
Output is correct |
72 |
Correct |
193 ms |
23900 KB |
Output is correct |
73 |
Correct |
253 ms |
23900 KB |
Output is correct |
74 |
Correct |
209 ms |
23900 KB |
Output is correct |
75 |
Correct |
243 ms |
23900 KB |
Output is correct |
76 |
Correct |
213 ms |
23900 KB |
Output is correct |
77 |
Correct |
216 ms |
30128 KB |
Output is correct |
78 |
Correct |
223 ms |
23900 KB |
Output is correct |
79 |
Correct |
233 ms |
23900 KB |
Output is correct |
80 |
Correct |
216 ms |
23900 KB |
Output is correct |