#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <map>
#include <set>
#include <complex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#define ft first
#define sc second
#define pb push_back
#define len(v) (int)v.size()
#define int ll
using namespace std;
typedef long long ll;
typedef long double ld;
int inf = (1LL << 45);
const int N = (1 << 18);
struct line {
int k, b;
int get(int x) {
return k * x + b;
}
bool operator < (const line& x) const {
return k < x.k;
}
};
struct node {
node* l;
node* r;
line now;
node(node* _l, node* _r, line _now) : l(_l), r(_r), now(_now) {}
};
struct lichao {
node* v;
lichao() {
v = new node(NULL, NULL, {0, inf});
}
int get(node* v, int l, int r, int x) {
int ans = v->now.get(x);
int m = (l + r) / 2;
if(m <= x) {
if(v->r == NULL)
return ans;
else
return min(ans, get(v->r, m, r, x));
}
else {
if(v->l == NULL)
return ans;
else
return min(ans, get(v->l, l, m, x));
}
}
void upd(node* v, int l, int r, line val) {
if(v->now.b == inf && v->now.k == 0) {
v->now = val;
return;
}
int m = (l + r) / 2;
bool lft = val.get(l) < v->now.get(l);
bool mid = val.get(m) < v->now.get(m);
if(mid)
swap(v->now, val);
if(r - l == 1)
return;
if(lft == mid) {
if(v->r == NULL) {
auto neww = new node(NULL, NULL, {0, inf});
v->r = neww;
}
upd(v->r, m, r, val);
return;
}
else {
if(v->l == NULL) {
auto neww = new node(NULL, NULL, {0, inf});
v->l = neww;
}
upd(v->l, l, m, val);
return;
}
}
int get(int x) {
return get(v, 0, inf, x);
}
void upd(line val) {
upd(v, 0, inf, val);
}
};
lichao tree[2 * N];
int get(int v, int l, int r, int vl, int vr, int X) {
if(r <= vl || vr <= l)
return inf;
if(vl <= l && r <= vr) {
return tree[v].get(X);
}
int m = (l + r) / 2;
return min(get(v * 2, l, m, vl, vr, X), get(v * 2 + 1, m, r, vl, vr, X));
}
void upd(int v, line val) {
if(v == 0)
return;
tree[v].upd(val);
upd(v / 2, val);
return;
}
signed main() {
#ifdef PC
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
auto t1 = clock();
int x, n, m, w, T;
cin >> x >> n >> m >> w >> T;
vector<int> s(n + 1);
vector<pair<int, int>> p(m);
vector<int> pref(m + 1, 0);
vector<int> cnt(m + 1, 0);
vector<int> d(m + 1, 0);
s[0] = 0;
for (int i = 1; i <= n; i++)
cin >> s[i];
s.pb(x);
n += 2;
sort(s.begin(), s.end());
for (int i = 0; i < m; i++) {
cin >> p[i].ft >> p[i].sc;
}
sort(p.begin(), p.end());
vector<int> have;
for (int i = 0; i < m; i++) {
pref[i + 1] = pref[i] + p[i].sc;
cnt[i] = (x - p[i].ft) / T + 1;
d[i] = p[i].ft;
have.pb(d[i]);
}
vector<vector<pair<int, int>>> can(m + 1);
for (int i = 1; i < n; i++) {
int driver = s[i] / T * T;
int minn = lower_bound(have.begin(), have.end(), max(0LL, s[i - 1] - driver)) - have.begin();
int lst = upper_bound(have.begin(), have.end(), s[i] - driver) - have.begin() - 1;
if(lst < minn)
continue;
can[lst].pb({s[i], minn});
// int lstt = -1, lst = -1;
// for (int j = 0; j < m; j++) {
// int time = s[i] / T * T + d[j];
// if(time > s[i])
// time -= T;
// if(time < s[i - 1])
// continue;
// if(time < driver)
// continue;
// if(time > lstt) {
// lstt = time;
// lst = j;
// }
// }
// if(lstt == -1)
// continue;
// int minn = lst;
// for (int j = m - 1; j >= 0; j--) {
// int time = s[i] / T * T + d[j];
// if(time > s[i])
// time -= T;
// if(time < s[i - 1])
// continue;
// if(time < driver)
// continue;
// minn = min(j, minn);
// // can[lst].pb({s[i], j});
// }
can[lst].pb({s[i], minn});
}
// if((clock() - t1) * 1.0 / CLOCKS_PER_SEC >= 0.45)
// return -1;
vector<int> dp(m + 1, 0);
for (int i = 0; i < m; i++) {
dp[i + 1] = dp[i] + cnt[i] * w;
upd(N + i, {-i, -pref[i] + dp[i]});
for (auto x : can[i]) {
int time = x.ft / T * T + d[i];
if(time > x.ft)
time -= T;
int X = time / T * w;
// cout << X << " " << x.ft << " " << x.sc << " " << i << " " << pref[i + 1] + (i + 1) * X + get(1, 0, N, i, i + 1, X) << " " << pref[i + 1] + (i + 1) * X + get(1, 0, N, x.sc, i + 1, X) << endl;
dp[i + 1] = min(dp[i + 1], pref[i + 1] + (i + 1) * X + get(1, 0, N, x.sc, i + 1, X));
}
// cout << i << " " << dp[i + 1] << endl;
}
cout << dp[m] + ((x / T + 1) * w) << endl;
return 0;
}
Compilation message
coach.cpp: In function 'int main()':
coach.cpp:133:7: warning: unused variable 't1' [-Wunused-variable]
auto t1 = clock();
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
29048 KB |
Output is correct |
2 |
Correct |
28 ms |
29048 KB |
Output is correct |
3 |
Correct |
28 ms |
29048 KB |
Output is correct |
4 |
Correct |
28 ms |
29048 KB |
Output is correct |
5 |
Correct |
28 ms |
29048 KB |
Output is correct |
6 |
Correct |
28 ms |
29048 KB |
Output is correct |
7 |
Correct |
29 ms |
29048 KB |
Output is correct |
8 |
Correct |
29 ms |
29048 KB |
Output is correct |
9 |
Correct |
28 ms |
29048 KB |
Output is correct |
10 |
Correct |
28 ms |
29048 KB |
Output is correct |
11 |
Correct |
29 ms |
29048 KB |
Output is correct |
12 |
Correct |
28 ms |
29048 KB |
Output is correct |
13 |
Correct |
31 ms |
29048 KB |
Output is correct |
14 |
Correct |
29 ms |
29048 KB |
Output is correct |
15 |
Correct |
29 ms |
29048 KB |
Output is correct |
16 |
Correct |
28 ms |
29048 KB |
Output is correct |
17 |
Correct |
30 ms |
29048 KB |
Output is correct |
18 |
Correct |
28 ms |
29052 KB |
Output is correct |
19 |
Correct |
30 ms |
29048 KB |
Output is correct |
20 |
Correct |
28 ms |
29048 KB |
Output is correct |
21 |
Correct |
29 ms |
29048 KB |
Output is correct |
22 |
Correct |
30 ms |
29048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
29048 KB |
Output is correct |
2 |
Correct |
28 ms |
29048 KB |
Output is correct |
3 |
Correct |
28 ms |
29048 KB |
Output is correct |
4 |
Correct |
28 ms |
29048 KB |
Output is correct |
5 |
Correct |
28 ms |
29048 KB |
Output is correct |
6 |
Correct |
28 ms |
29048 KB |
Output is correct |
7 |
Correct |
29 ms |
29048 KB |
Output is correct |
8 |
Correct |
29 ms |
29048 KB |
Output is correct |
9 |
Correct |
28 ms |
29048 KB |
Output is correct |
10 |
Correct |
28 ms |
29048 KB |
Output is correct |
11 |
Correct |
29 ms |
29048 KB |
Output is correct |
12 |
Correct |
28 ms |
29048 KB |
Output is correct |
13 |
Correct |
31 ms |
29048 KB |
Output is correct |
14 |
Correct |
29 ms |
29048 KB |
Output is correct |
15 |
Correct |
29 ms |
29048 KB |
Output is correct |
16 |
Correct |
28 ms |
29048 KB |
Output is correct |
17 |
Correct |
30 ms |
29048 KB |
Output is correct |
18 |
Correct |
28 ms |
29052 KB |
Output is correct |
19 |
Correct |
30 ms |
29048 KB |
Output is correct |
20 |
Correct |
28 ms |
29048 KB |
Output is correct |
21 |
Correct |
29 ms |
29048 KB |
Output is correct |
22 |
Correct |
30 ms |
29048 KB |
Output is correct |
23 |
Correct |
30 ms |
29176 KB |
Output is correct |
24 |
Correct |
29 ms |
29176 KB |
Output is correct |
25 |
Correct |
29 ms |
29176 KB |
Output is correct |
26 |
Correct |
30 ms |
29176 KB |
Output is correct |
27 |
Correct |
29 ms |
29176 KB |
Output is correct |
28 |
Correct |
30 ms |
29152 KB |
Output is correct |
29 |
Correct |
29 ms |
29176 KB |
Output is correct |
30 |
Correct |
29 ms |
29176 KB |
Output is correct |
31 |
Correct |
31 ms |
29176 KB |
Output is correct |
32 |
Correct |
28 ms |
29176 KB |
Output is correct |
33 |
Correct |
28 ms |
29176 KB |
Output is correct |
34 |
Correct |
28 ms |
29176 KB |
Output is correct |
35 |
Correct |
28 ms |
29180 KB |
Output is correct |
36 |
Correct |
29 ms |
29176 KB |
Output is correct |
37 |
Correct |
29 ms |
29176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
29048 KB |
Output is correct |
2 |
Correct |
28 ms |
29048 KB |
Output is correct |
3 |
Correct |
28 ms |
29048 KB |
Output is correct |
4 |
Correct |
28 ms |
29048 KB |
Output is correct |
5 |
Correct |
28 ms |
29048 KB |
Output is correct |
6 |
Correct |
28 ms |
29048 KB |
Output is correct |
7 |
Correct |
29 ms |
29048 KB |
Output is correct |
8 |
Correct |
29 ms |
29048 KB |
Output is correct |
9 |
Correct |
28 ms |
29048 KB |
Output is correct |
10 |
Correct |
28 ms |
29048 KB |
Output is correct |
11 |
Correct |
29 ms |
29048 KB |
Output is correct |
12 |
Correct |
28 ms |
29048 KB |
Output is correct |
13 |
Correct |
31 ms |
29048 KB |
Output is correct |
14 |
Correct |
29 ms |
29048 KB |
Output is correct |
15 |
Correct |
29 ms |
29048 KB |
Output is correct |
16 |
Correct |
28 ms |
29048 KB |
Output is correct |
17 |
Correct |
30 ms |
29048 KB |
Output is correct |
18 |
Correct |
28 ms |
29052 KB |
Output is correct |
19 |
Correct |
30 ms |
29048 KB |
Output is correct |
20 |
Correct |
28 ms |
29048 KB |
Output is correct |
21 |
Correct |
29 ms |
29048 KB |
Output is correct |
22 |
Correct |
30 ms |
29048 KB |
Output is correct |
23 |
Correct |
30 ms |
29176 KB |
Output is correct |
24 |
Correct |
29 ms |
29176 KB |
Output is correct |
25 |
Correct |
29 ms |
29176 KB |
Output is correct |
26 |
Correct |
30 ms |
29176 KB |
Output is correct |
27 |
Correct |
29 ms |
29176 KB |
Output is correct |
28 |
Correct |
30 ms |
29152 KB |
Output is correct |
29 |
Correct |
29 ms |
29176 KB |
Output is correct |
30 |
Correct |
29 ms |
29176 KB |
Output is correct |
31 |
Correct |
31 ms |
29176 KB |
Output is correct |
32 |
Correct |
28 ms |
29176 KB |
Output is correct |
33 |
Correct |
28 ms |
29176 KB |
Output is correct |
34 |
Correct |
28 ms |
29176 KB |
Output is correct |
35 |
Correct |
28 ms |
29180 KB |
Output is correct |
36 |
Correct |
29 ms |
29176 KB |
Output is correct |
37 |
Correct |
29 ms |
29176 KB |
Output is correct |
38 |
Correct |
38 ms |
30328 KB |
Output is correct |
39 |
Correct |
39 ms |
30228 KB |
Output is correct |
40 |
Correct |
40 ms |
30072 KB |
Output is correct |
41 |
Correct |
38 ms |
29944 KB |
Output is correct |
42 |
Correct |
38 ms |
30072 KB |
Output is correct |
43 |
Correct |
39 ms |
30072 KB |
Output is correct |
44 |
Correct |
38 ms |
30200 KB |
Output is correct |
45 |
Correct |
39 ms |
30072 KB |
Output is correct |
46 |
Correct |
38 ms |
30968 KB |
Output is correct |
47 |
Correct |
37 ms |
29944 KB |
Output is correct |
48 |
Correct |
40 ms |
30328 KB |
Output is correct |
49 |
Correct |
37 ms |
30072 KB |
Output is correct |
50 |
Correct |
39 ms |
30328 KB |
Output is correct |
51 |
Correct |
38 ms |
30332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
29048 KB |
Output is correct |
2 |
Correct |
28 ms |
29048 KB |
Output is correct |
3 |
Correct |
28 ms |
29048 KB |
Output is correct |
4 |
Correct |
28 ms |
29048 KB |
Output is correct |
5 |
Correct |
28 ms |
29048 KB |
Output is correct |
6 |
Correct |
28 ms |
29048 KB |
Output is correct |
7 |
Correct |
29 ms |
29048 KB |
Output is correct |
8 |
Correct |
29 ms |
29048 KB |
Output is correct |
9 |
Correct |
28 ms |
29048 KB |
Output is correct |
10 |
Correct |
28 ms |
29048 KB |
Output is correct |
11 |
Correct |
29 ms |
29048 KB |
Output is correct |
12 |
Correct |
28 ms |
29048 KB |
Output is correct |
13 |
Correct |
31 ms |
29048 KB |
Output is correct |
14 |
Correct |
29 ms |
29048 KB |
Output is correct |
15 |
Correct |
29 ms |
29048 KB |
Output is correct |
16 |
Correct |
28 ms |
29048 KB |
Output is correct |
17 |
Correct |
30 ms |
29048 KB |
Output is correct |
18 |
Correct |
28 ms |
29052 KB |
Output is correct |
19 |
Correct |
30 ms |
29048 KB |
Output is correct |
20 |
Correct |
28 ms |
29048 KB |
Output is correct |
21 |
Correct |
29 ms |
29048 KB |
Output is correct |
22 |
Correct |
30 ms |
29048 KB |
Output is correct |
23 |
Correct |
30 ms |
29176 KB |
Output is correct |
24 |
Correct |
29 ms |
29176 KB |
Output is correct |
25 |
Correct |
29 ms |
29176 KB |
Output is correct |
26 |
Correct |
30 ms |
29176 KB |
Output is correct |
27 |
Correct |
29 ms |
29176 KB |
Output is correct |
28 |
Correct |
30 ms |
29152 KB |
Output is correct |
29 |
Correct |
29 ms |
29176 KB |
Output is correct |
30 |
Correct |
29 ms |
29176 KB |
Output is correct |
31 |
Correct |
31 ms |
29176 KB |
Output is correct |
32 |
Correct |
28 ms |
29176 KB |
Output is correct |
33 |
Correct |
28 ms |
29176 KB |
Output is correct |
34 |
Correct |
28 ms |
29176 KB |
Output is correct |
35 |
Correct |
28 ms |
29180 KB |
Output is correct |
36 |
Correct |
29 ms |
29176 KB |
Output is correct |
37 |
Correct |
29 ms |
29176 KB |
Output is correct |
38 |
Correct |
38 ms |
30328 KB |
Output is correct |
39 |
Correct |
39 ms |
30228 KB |
Output is correct |
40 |
Correct |
40 ms |
30072 KB |
Output is correct |
41 |
Correct |
38 ms |
29944 KB |
Output is correct |
42 |
Correct |
38 ms |
30072 KB |
Output is correct |
43 |
Correct |
39 ms |
30072 KB |
Output is correct |
44 |
Correct |
38 ms |
30200 KB |
Output is correct |
45 |
Correct |
39 ms |
30072 KB |
Output is correct |
46 |
Correct |
38 ms |
30968 KB |
Output is correct |
47 |
Correct |
37 ms |
29944 KB |
Output is correct |
48 |
Correct |
40 ms |
30328 KB |
Output is correct |
49 |
Correct |
37 ms |
30072 KB |
Output is correct |
50 |
Correct |
39 ms |
30328 KB |
Output is correct |
51 |
Correct |
38 ms |
30332 KB |
Output is correct |
52 |
Correct |
1783 ms |
137432 KB |
Output is correct |
53 |
Correct |
1501 ms |
143576 KB |
Output is correct |
54 |
Correct |
1201 ms |
118716 KB |
Output is correct |
55 |
Correct |
1123 ms |
116312 KB |
Output is correct |
56 |
Correct |
1049 ms |
112220 KB |
Output is correct |
57 |
Correct |
1271 ms |
132312 KB |
Output is correct |
58 |
Correct |
1062 ms |
111192 KB |
Output is correct |
59 |
Correct |
1128 ms |
116184 KB |
Output is correct |
60 |
Correct |
1182 ms |
118168 KB |
Output is correct |
61 |
Correct |
1139 ms |
116312 KB |
Output is correct |
62 |
Correct |
1247 ms |
122840 KB |
Output is correct |
63 |
Correct |
980 ms |
219484 KB |
Output is correct |
64 |
Correct |
983 ms |
125424 KB |
Output is correct |
65 |
Correct |
1607 ms |
136668 KB |
Output is correct |
66 |
Correct |
1096 ms |
112600 KB |
Output is correct |
67 |
Correct |
1887 ms |
153524 KB |
Output is correct |
68 |
Correct |
1835 ms |
147036 KB |
Output is correct |
69 |
Correct |
1967 ms |
143844 KB |
Output is correct |
70 |
Correct |
1981 ms |
143808 KB |
Output is correct |
71 |
Correct |
1922 ms |
143792 KB |
Output is correct |
72 |
Correct |
1969 ms |
143448 KB |
Output is correct |
73 |
Correct |
1884 ms |
140996 KB |
Output is correct |
74 |
Correct |
1608 ms |
133468 KB |
Output is correct |
75 |
Correct |
1303 ms |
121436 KB |
Output is correct |
76 |
Correct |
1235 ms |
111848 KB |
Output is correct |
77 |
Correct |
1114 ms |
125836 KB |
Output is correct |
78 |
Correct |
1151 ms |
138712 KB |
Output is correct |
79 |
Correct |
1711 ms |
142600 KB |
Output is correct |
80 |
Correct |
1680 ms |
142680 KB |
Output is correct |