#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[N], psh[N], pref[N], po[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 |
8536 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 |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8668 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 |
8552 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8660 KB |
Output is correct |
15 |
Correct |
1 ms |
8552 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
1 ms |
8540 KB |
Output is correct |
19 |
Correct |
1 ms |
8536 KB |
Output is correct |
20 |
Correct |
1 ms |
8664 KB |
Output is correct |
21 |
Correct |
1 ms |
8540 KB |
Output is correct |
22 |
Correct |
1 ms |
8544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 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 |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8668 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 |
8552 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8660 KB |
Output is correct |
15 |
Correct |
1 ms |
8552 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
1 ms |
8540 KB |
Output is correct |
19 |
Correct |
1 ms |
8536 KB |
Output is correct |
20 |
Correct |
1 ms |
8664 KB |
Output is correct |
21 |
Correct |
1 ms |
8540 KB |
Output is correct |
22 |
Correct |
1 ms |
8544 KB |
Output is correct |
23 |
Correct |
1 ms |
8536 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 |
8660 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 |
8540 KB |
Output is correct |
37 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 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 |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8668 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 |
8552 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8660 KB |
Output is correct |
15 |
Correct |
1 ms |
8552 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
1 ms |
8540 KB |
Output is correct |
19 |
Correct |
1 ms |
8536 KB |
Output is correct |
20 |
Correct |
1 ms |
8664 KB |
Output is correct |
21 |
Correct |
1 ms |
8540 KB |
Output is correct |
22 |
Correct |
1 ms |
8544 KB |
Output is correct |
23 |
Correct |
1 ms |
8536 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 |
8660 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 |
8540 KB |
Output is correct |
37 |
Correct |
1 ms |
8540 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 |
8796 KB |
Output is correct |
41 |
Correct |
1 ms |
8796 KB |
Output is correct |
42 |
Correct |
2 ms |
8900 KB |
Output is correct |
43 |
Correct |
2 ms |
8796 KB |
Output is correct |
44 |
Correct |
2 ms |
8796 KB |
Output is correct |
45 |
Correct |
1 ms |
8796 KB |
Output is correct |
46 |
Correct |
1 ms |
9052 KB |
Output is correct |
47 |
Correct |
2 ms |
8796 KB |
Output is correct |
48 |
Correct |
1 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 |
8536 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 |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8668 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 |
8552 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8660 KB |
Output is correct |
15 |
Correct |
1 ms |
8552 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
1 ms |
8540 KB |
Output is correct |
19 |
Correct |
1 ms |
8536 KB |
Output is correct |
20 |
Correct |
1 ms |
8664 KB |
Output is correct |
21 |
Correct |
1 ms |
8540 KB |
Output is correct |
22 |
Correct |
1 ms |
8544 KB |
Output is correct |
23 |
Correct |
1 ms |
8536 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 |
8660 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 |
8540 KB |
Output is correct |
37 |
Correct |
1 ms |
8540 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 |
8796 KB |
Output is correct |
41 |
Correct |
1 ms |
8796 KB |
Output is correct |
42 |
Correct |
2 ms |
8900 KB |
Output is correct |
43 |
Correct |
2 ms |
8796 KB |
Output is correct |
44 |
Correct |
2 ms |
8796 KB |
Output is correct |
45 |
Correct |
1 ms |
8796 KB |
Output is correct |
46 |
Correct |
1 ms |
9052 KB |
Output is correct |
47 |
Correct |
2 ms |
8796 KB |
Output is correct |
48 |
Correct |
1 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 |
Incorrect |
83 ms |
27332 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |