#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll x, w, t; int n, m;
ll s[200005], pref[200005], d[200005];
pair<ll, ll> p[200005];
ll v[200005];
bool Q;
struct Line{
mutable ll m, c, pt;
bool operator<(const Line& rhs) const{
return Q ? pt < rhs.pt : m < rhs.m;
}
};
struct LineContainer : multiset<Line>{
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()){
x -> pt = inf;
return false;
}
if(x -> m == y -> m)
x -> pt = x -> m > y -> m ? inf : -inf;
else
x -> pt = div(y -> c - x -> c, x -> m - y -> m);
return x -> pt >= y -> pt;
}
void add(ll m, ll c){
auto z = insert({m, c, 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) -> pt >= y -> pt)
isect(x, erase(y));
}
ll query(ll x){
Q = 1; auto l = *lower_bound({0, 0, x}); Q = 0;
return l.m * x + l.c;
}
} cht;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> x >> n >> m >> w >> t;
for(int i = 1; i <= n; i ++) cin >> s[i];
s[n + 1] = x;
sort(s + 1, s + n + 2); reverse(s + 1, s + n + 2);
for(int i = 1; i <= m; i ++) cin >> p[i].first >> p[i].second;
sort(p + 1, p + m + 1);
for(int i = 1; i <= m; i ++){
d[i] = p[i].first;
pref[i] = pref[i - 1] + p[i].second;
}
for(int i = 1; i <= n + 1; i ++)
v[lower_bound(d + 1, d + m + 1, s[i] % t) - d - 1] = s[i];
ll ans = 0ll;
cht.add(0, 0);
for(int i = 1; i <= m; i ++){
ans += (x - d[i]) / t * w + w;
if(v[i]) ans = min(ans, -cht.query(v[i] / t * w) + v[i] / t * w * i + pref[i]);
cht.add(i, pref[i] - ans);
}
ans += x / t * w + w;
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
37 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
37 |
Correct |
0 ms |
384 KB |
Output is correct |
38 |
Correct |
2 ms |
512 KB |
Output is correct |
39 |
Correct |
2 ms |
512 KB |
Output is correct |
40 |
Correct |
2 ms |
512 KB |
Output is correct |
41 |
Correct |
2 ms |
512 KB |
Output is correct |
42 |
Correct |
2 ms |
512 KB |
Output is correct |
43 |
Correct |
2 ms |
512 KB |
Output is correct |
44 |
Correct |
2 ms |
512 KB |
Output is correct |
45 |
Correct |
2 ms |
512 KB |
Output is correct |
46 |
Correct |
2 ms |
640 KB |
Output is correct |
47 |
Correct |
2 ms |
512 KB |
Output is correct |
48 |
Correct |
2 ms |
512 KB |
Output is correct |
49 |
Correct |
3 ms |
512 KB |
Output is correct |
50 |
Correct |
2 ms |
512 KB |
Output is correct |
51 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
37 |
Correct |
0 ms |
384 KB |
Output is correct |
38 |
Correct |
2 ms |
512 KB |
Output is correct |
39 |
Correct |
2 ms |
512 KB |
Output is correct |
40 |
Correct |
2 ms |
512 KB |
Output is correct |
41 |
Correct |
2 ms |
512 KB |
Output is correct |
42 |
Correct |
2 ms |
512 KB |
Output is correct |
43 |
Correct |
2 ms |
512 KB |
Output is correct |
44 |
Correct |
2 ms |
512 KB |
Output is correct |
45 |
Correct |
2 ms |
512 KB |
Output is correct |
46 |
Correct |
2 ms |
640 KB |
Output is correct |
47 |
Correct |
2 ms |
512 KB |
Output is correct |
48 |
Correct |
2 ms |
512 KB |
Output is correct |
49 |
Correct |
3 ms |
512 KB |
Output is correct |
50 |
Correct |
2 ms |
512 KB |
Output is correct |
51 |
Correct |
2 ms |
512 KB |
Output is correct |
52 |
Correct |
174 ms |
15480 KB |
Output is correct |
53 |
Correct |
163 ms |
15512 KB |
Output is correct |
54 |
Correct |
135 ms |
14584 KB |
Output is correct |
55 |
Correct |
138 ms |
14840 KB |
Output is correct |
56 |
Correct |
139 ms |
15096 KB |
Output is correct |
57 |
Correct |
139 ms |
14968 KB |
Output is correct |
58 |
Correct |
142 ms |
15480 KB |
Output is correct |
59 |
Correct |
136 ms |
14840 KB |
Output is correct |
60 |
Correct |
170 ms |
14584 KB |
Output is correct |
61 |
Correct |
136 ms |
14840 KB |
Output is correct |
62 |
Correct |
139 ms |
14840 KB |
Output is correct |
63 |
Correct |
178 ms |
26232 KB |
Output is correct |
64 |
Correct |
126 ms |
13944 KB |
Output is correct |
65 |
Correct |
157 ms |
15480 KB |
Output is correct |
66 |
Correct |
166 ms |
15480 KB |
Output is correct |
67 |
Correct |
161 ms |
15480 KB |
Output is correct |
68 |
Correct |
164 ms |
15480 KB |
Output is correct |
69 |
Correct |
171 ms |
15224 KB |
Output is correct |
70 |
Correct |
184 ms |
15224 KB |
Output is correct |
71 |
Correct |
175 ms |
15352 KB |
Output is correct |
72 |
Correct |
176 ms |
15224 KB |
Output is correct |
73 |
Correct |
174 ms |
15336 KB |
Output is correct |
74 |
Correct |
181 ms |
15252 KB |
Output is correct |
75 |
Correct |
205 ms |
15352 KB |
Output is correct |
76 |
Correct |
191 ms |
15584 KB |
Output is correct |
77 |
Correct |
144 ms |
15224 KB |
Output is correct |
78 |
Correct |
146 ms |
15480 KB |
Output is correct |
79 |
Correct |
168 ms |
14840 KB |
Output is correct |
80 |
Correct |
165 ms |
14840 KB |
Output is correct |