#include <bits/stdc++.h>
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef long double ld;
typedef pair <ld, ld> pdd;
const int N = 2e5 + 7;
ll h, n, m, w, t;
ll g[N], c[N], d[N], dp[2*N], psh[2*N], pref[2*N], po[2*N];
vector <pair <ll, pii> > v;
bool ccw(pdd x, pdd y, pdd z) {return x.F*(y.S-z.S)+y.F*(z.S-x.S)+z.F*(x.S-y.S) > 0;}
int main () {
FIO;
cin >> h >> n >> m >> w >> t;
for (int i = 0; i < n; i++) cin >> g[i];
g[n++] = h;
for (int i = 0; i < m; i++) cin >> d[i] >> c[i];
for (int i = 0; i < n; i++) {
v.pb({g[i]%t, {i, 0}});
}
for (int i = 0; i < m; i++) {
v.pb({d[i], {i, 1}});
}
sort(all(v));
vector <pair <int, pdd> > u;
ll la = 0, sh = h/t+1;
psh[0] = sh;
for (int i = 0; i < n+m; i++) {
psh[i+1] = psh[i];
pref[i+1] = pref[i];
po[i+1] = po[i];
int z = v[i].S.F;
if (!v[i].S.S) {
dp[i] = la;
if (z == n-1) sh--;
ll R = g[z]/t;
auto f = [&](int x) {return dp[x]+pref[i+1]-pref[x]+R*w*(po[i+1]-po[x])-(psh[i+1]-psh[x])*w;};
if (u.empty()) continue;
int lo = 0, hi = u.size()-1;
while (lo < hi) {
int mid = (lo + hi) / 2;
if (f(u[mid].F) < f(u[mid+1].F)) hi = mid;
else lo = mid+1;
}
dp[i] = min(dp[i], f(u[lo].F));
la = dp[i];
}
else {
po[i+1]++;
psh[i+1] += sh;
pref[i+1] += c[z];
dp[i] = la;
pdd p = {-po[i], dp[i]-pref[i]+psh[i]*w};
while (u.size() > 1 && ccw(u[u.size()-2].S, u.back().S, p)) u.pop_back();
u.pb({i, p});
}
}
cout << dp[n+m-1]+psh[n+m]*w << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8536 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8536 KB |
Output is correct |
13 |
Correct |
1 ms |
8536 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 |
8660 KB |
Output is correct |
18 |
Correct |
1 ms |
8540 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
1 ms |
8540 KB |
Output is correct |
22 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8536 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8536 KB |
Output is correct |
13 |
Correct |
1 ms |
8536 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 |
8660 KB |
Output is correct |
18 |
Correct |
1 ms |
8540 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 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 |
1 ms |
8540 KB |
Output is correct |
24 |
Correct |
1 ms |
8540 KB |
Output is correct |
25 |
Correct |
1 ms |
8540 KB |
Output is correct |
26 |
Correct |
1 ms |
8540 KB |
Output is correct |
27 |
Correct |
1 ms |
8540 KB |
Output is correct |
28 |
Correct |
1 ms |
8540 KB |
Output is correct |
29 |
Correct |
1 ms |
8540 KB |
Output is correct |
30 |
Correct |
1 ms |
8540 KB |
Output is correct |
31 |
Correct |
1 ms |
8540 KB |
Output is correct |
32 |
Correct |
1 ms |
8540 KB |
Output is correct |
33 |
Correct |
1 ms |
8540 KB |
Output is correct |
34 |
Correct |
1 ms |
8540 KB |
Output is correct |
35 |
Correct |
1 ms |
8540 KB |
Output is correct |
36 |
Correct |
1 ms |
8536 KB |
Output is correct |
37 |
Correct |
1 ms |
8536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8536 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8536 KB |
Output is correct |
13 |
Correct |
1 ms |
8536 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 |
8660 KB |
Output is correct |
18 |
Correct |
1 ms |
8540 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 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 |
1 ms |
8540 KB |
Output is correct |
24 |
Correct |
1 ms |
8540 KB |
Output is correct |
25 |
Correct |
1 ms |
8540 KB |
Output is correct |
26 |
Correct |
1 ms |
8540 KB |
Output is correct |
27 |
Correct |
1 ms |
8540 KB |
Output is correct |
28 |
Correct |
1 ms |
8540 KB |
Output is correct |
29 |
Correct |
1 ms |
8540 KB |
Output is correct |
30 |
Correct |
1 ms |
8540 KB |
Output is correct |
31 |
Correct |
1 ms |
8540 KB |
Output is correct |
32 |
Correct |
1 ms |
8540 KB |
Output is correct |
33 |
Correct |
1 ms |
8540 KB |
Output is correct |
34 |
Correct |
1 ms |
8540 KB |
Output is correct |
35 |
Correct |
1 ms |
8540 KB |
Output is correct |
36 |
Correct |
1 ms |
8536 KB |
Output is correct |
37 |
Correct |
1 ms |
8536 KB |
Output is correct |
38 |
Correct |
2 ms |
8796 KB |
Output is correct |
39 |
Correct |
2 ms |
8796 KB |
Output is correct |
40 |
Correct |
2 ms |
8916 KB |
Output is correct |
41 |
Correct |
1 ms |
8796 KB |
Output is correct |
42 |
Correct |
1 ms |
8796 KB |
Output is correct |
43 |
Correct |
1 ms |
8792 KB |
Output is correct |
44 |
Correct |
1 ms |
8796 KB |
Output is correct |
45 |
Correct |
2 ms |
8796 KB |
Output is correct |
46 |
Correct |
1 ms |
8796 KB |
Output is correct |
47 |
Correct |
2 ms |
8796 KB |
Output is correct |
48 |
Correct |
2 ms |
8796 KB |
Output is correct |
49 |
Correct |
2 ms |
8796 KB |
Output is correct |
50 |
Correct |
1 ms |
8796 KB |
Output is correct |
51 |
Correct |
2 ms |
8796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8536 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8536 KB |
Output is correct |
13 |
Correct |
1 ms |
8536 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 |
8660 KB |
Output is correct |
18 |
Correct |
1 ms |
8540 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 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 |
1 ms |
8540 KB |
Output is correct |
24 |
Correct |
1 ms |
8540 KB |
Output is correct |
25 |
Correct |
1 ms |
8540 KB |
Output is correct |
26 |
Correct |
1 ms |
8540 KB |
Output is correct |
27 |
Correct |
1 ms |
8540 KB |
Output is correct |
28 |
Correct |
1 ms |
8540 KB |
Output is correct |
29 |
Correct |
1 ms |
8540 KB |
Output is correct |
30 |
Correct |
1 ms |
8540 KB |
Output is correct |
31 |
Correct |
1 ms |
8540 KB |
Output is correct |
32 |
Correct |
1 ms |
8540 KB |
Output is correct |
33 |
Correct |
1 ms |
8540 KB |
Output is correct |
34 |
Correct |
1 ms |
8540 KB |
Output is correct |
35 |
Correct |
1 ms |
8540 KB |
Output is correct |
36 |
Correct |
1 ms |
8536 KB |
Output is correct |
37 |
Correct |
1 ms |
8536 KB |
Output is correct |
38 |
Correct |
2 ms |
8796 KB |
Output is correct |
39 |
Correct |
2 ms |
8796 KB |
Output is correct |
40 |
Correct |
2 ms |
8916 KB |
Output is correct |
41 |
Correct |
1 ms |
8796 KB |
Output is correct |
42 |
Correct |
1 ms |
8796 KB |
Output is correct |
43 |
Correct |
1 ms |
8792 KB |
Output is correct |
44 |
Correct |
1 ms |
8796 KB |
Output is correct |
45 |
Correct |
2 ms |
8796 KB |
Output is correct |
46 |
Correct |
1 ms |
8796 KB |
Output is correct |
47 |
Correct |
2 ms |
8796 KB |
Output is correct |
48 |
Correct |
2 ms |
8796 KB |
Output is correct |
49 |
Correct |
2 ms |
8796 KB |
Output is correct |
50 |
Correct |
1 ms |
8796 KB |
Output is correct |
51 |
Correct |
2 ms |
8796 KB |
Output is correct |
52 |
Correct |
80 ms |
27464 KB |
Output is correct |
53 |
Correct |
80 ms |
33712 KB |
Output is correct |
54 |
Correct |
82 ms |
38284 KB |
Output is correct |
55 |
Correct |
78 ms |
36780 KB |
Output is correct |
56 |
Correct |
85 ms |
33156 KB |
Output is correct |
57 |
Correct |
76 ms |
33420 KB |
Output is correct |
58 |
Correct |
77 ms |
33428 KB |
Output is correct |
59 |
Correct |
77 ms |
34672 KB |
Output is correct |
60 |
Correct |
82 ms |
34996 KB |
Output is correct |
61 |
Correct |
80 ms |
34960 KB |
Output is correct |
62 |
Correct |
80 ms |
34512 KB |
Output is correct |
63 |
Correct |
104 ms |
50348 KB |
Output is correct |
64 |
Correct |
59 ms |
33216 KB |
Output is correct |
65 |
Correct |
81 ms |
33712 KB |
Output is correct |
66 |
Correct |
81 ms |
33448 KB |
Output is correct |
67 |
Correct |
83 ms |
33404 KB |
Output is correct |
68 |
Correct |
83 ms |
32988 KB |
Output is correct |
69 |
Correct |
83 ms |
33552 KB |
Output is correct |
70 |
Correct |
85 ms |
33140 KB |
Output is correct |
71 |
Correct |
83 ms |
34476 KB |
Output is correct |
72 |
Correct |
93 ms |
32920 KB |
Output is correct |
73 |
Correct |
84 ms |
34428 KB |
Output is correct |
74 |
Correct |
83 ms |
34120 KB |
Output is correct |
75 |
Correct |
81 ms |
33424 KB |
Output is correct |
76 |
Correct |
87 ms |
33680 KB |
Output is correct |
77 |
Correct |
108 ms |
44928 KB |
Output is correct |
78 |
Correct |
83 ms |
34220 KB |
Output is correct |
79 |
Correct |
85 ms |
33664 KB |
Output is correct |
80 |
Correct |
81 ms |
32528 KB |
Output is correct |