#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define sz size
ll x,w,t;
int n,m;
const int mxN = 2e5+1;
ll points[mxN];
pii pass[mxN];
ll dp[mxN];
int idx[mxN];
int nextv[mxN];
ll psum[mxN];
struct cmp {
bool operator() (int a, int b) const {
return (points[idx[a]] > points[idx[b]]);
}
};
ll qu(int a, int b){
if (a < b) swap(a,b);
ll v1 = dp[a];
ll v2 = dp[b];
if (nextv[a] > 0) v2 += psum[nextv[a]-1];
if (nextv[b] > 0) v2 -= psum[nextv[b]-1];
v2 += (nextv[a] - nextv[b]) * (points[idx[b]] / t) * w;
if (points[idx[a]] > points[idx[b]]){
swap(a,b);
swap(v1,v2);
}
if (points[idx[b]]/t == points[idx[a]]/t){
if (v1 > v2){
return (ll) 1 * 1e18;
} else {
return (ll) -1 * 1e18;
}
}
return max(nextv[a],nextv[b]) - 1 + (int) ceil((double) (v1 - v2) / (double) ((points[idx[b]]/t - points[idx[a]]/t) * w));
}
int main()
{
//psum[0] = 0;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> x >> n >> m >> w >> t;
n++;
map<ll,ll> exist;
ll a;
int cnt = 0;
for (int i =0; i < n; i++){
if (i == n-1) a = x;
else cin >> a;
if (exist.find(a%t) == exist.end()){
// cout << a%t << " L\n";
points[i-cnt] = a;
exist[a%t] = i-cnt;
} else {
cnt++;
points[exist[a%t]] = min(points[exist[a%t]],a);
}
}
n -= cnt;
for (int i =0; i < m; i++) cin >> pass[i].f >> pass[i].s;
vector<pii> all(n+m);
for (int i = 0; i < n; i++) all[i] = {points[i] % t, i};
for (int i = 0; i < m; i++) all[i+n] = {pass[i].f, i+n};
sort(all.begin(),all.end());
/* for (int i =0; i < n; i++){
cout << points[i] << " ";
}
cout << '\n';
for (int i =0; i < m; i++) cout << pass[i].f << "," << pass[i].s << " ";
cout << '\n';*/
ll alt;
ll best = 0;
cnt = 0;
int cnt2 = 0;
set<int,cmp> curr;
for (int i =n+m-1; i >= 0; i--){
// cout << all[i].f << ',' << all[i].s << ": ";
if (all[i].s < n){
/* cout << " bef ";
for (auto it = curr.begin(); it != curr.end(); it++){
cout << (*it) << " ";
}
cout << '\n';*/
idx[cnt2] = all[i].s;
nextv[cnt2] = cnt;
dp[cnt2] = best;
auto it = curr.lower_bound(cnt2);
if (it != curr.end()){
auto it2 = it;
it2++;
while (it2 != curr.end() && qu(cnt2,(*it)) >= qu((*it),(*it2))){
curr.erase(it);
it = it2;
it2++;
}
it = curr.lower_bound(cnt2);
}
if (it != curr.begin()){
it--;
if (it != curr.begin()){
auto it2 = it;
it2--;
while (qu(cnt2,(*it)) <= qu((*it),(*it2))){
curr.erase(it);
it = it2;
if (it2 == curr.begin()){
break;
}
it2--;
}
}
it = curr.lower_bound(cnt2);
}
if (it != curr.end() && it != curr.begin()){
auto it2 = it;
it2--;
if (qu(cnt2,*it) > qu(cnt2, *it2)){
curr.insert(cnt2);
}
} else {
curr.insert(cnt2);
}
cnt2++;
/* cout << " aft ";
for (auto it = curr.begin(); it != curr.end(); it++){
cout << (*it) << " ";
}
cout << '\n';*/
} else {
all[i].s -= n;
psum[cnt] = pass[all[i].s].s;
if (cnt > 0) psum[cnt] += psum[cnt-1];
while (curr.sz() > 1){
auto it = curr.begin();
auto it2 = it;
it2++;
// cout << (*it) << "-" << (*it2) << " " << qu((*it),(*it2)) << '\n';
if (qu((*it),(*it2)) <= cnt){
curr.erase(it);
} else {
break;
}
}
ll alt = 1e18;
if (curr.sz() > 0){
int cidx = *(curr.begin());
//cout << cidx << " C ";
alt = dp[cidx] + psum[cnt];
if (nextv[cidx] > 0) alt -= psum[nextv[cidx]-1];
alt += (points[idx[cidx]] / t) * w * (cnt - nextv[cidx]+1);
}
ll ctimes = x / t;
if (x%t > all[i].f){
ctimes++;
}
best = min(best+ctimes*w,alt);
// cout << best << '\n';
cnt++;
}
// cout << '\n';
}
best += w * (x/t+1);
cout << best << '\n';
return 0;
}
Compilation message
coach.cpp: In function 'int main()':
coach.cpp:88:8: warning: unused variable 'alt' [-Wunused-variable]
88 | ll alt;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 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 |
5 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8660 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8536 KB |
Output is correct |
11 |
Correct |
1 ms |
8660 KB |
Output is correct |
12 |
Correct |
1 ms |
8536 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
8540 KB |
Output is correct |
16 |
Correct |
2 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
4 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 |
2 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 |
5 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8660 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8536 KB |
Output is correct |
11 |
Correct |
1 ms |
8660 KB |
Output is correct |
12 |
Correct |
1 ms |
8536 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
8540 KB |
Output is correct |
16 |
Correct |
2 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
4 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 |
2 ms |
8660 KB |
Output is correct |
26 |
Correct |
1 ms |
8536 KB |
Output is correct |
27 |
Correct |
1 ms |
8540 KB |
Output is correct |
28 |
Correct |
1 ms |
8540 KB |
Output is correct |
29 |
Correct |
3 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 |
8680 KB |
Output is correct |
35 |
Correct |
2 ms |
8536 KB |
Output is correct |
36 |
Correct |
1 ms |
8656 KB |
Output is correct |
37 |
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 |
2 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 |
5 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8660 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8536 KB |
Output is correct |
11 |
Correct |
1 ms |
8660 KB |
Output is correct |
12 |
Correct |
1 ms |
8536 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
8540 KB |
Output is correct |
16 |
Correct |
2 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
4 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 |
2 ms |
8660 KB |
Output is correct |
26 |
Correct |
1 ms |
8536 KB |
Output is correct |
27 |
Correct |
1 ms |
8540 KB |
Output is correct |
28 |
Correct |
1 ms |
8540 KB |
Output is correct |
29 |
Correct |
3 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 |
8680 KB |
Output is correct |
35 |
Correct |
2 ms |
8536 KB |
Output is correct |
36 |
Correct |
1 ms |
8656 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 |
8792 KB |
Output is correct |
41 |
Correct |
3 ms |
8796 KB |
Output is correct |
42 |
Correct |
3 ms |
8796 KB |
Output is correct |
43 |
Correct |
2 ms |
8664 KB |
Output is correct |
44 |
Correct |
3 ms |
8792 KB |
Output is correct |
45 |
Correct |
3 ms |
8792 KB |
Output is correct |
46 |
Correct |
2 ms |
8796 KB |
Output is correct |
47 |
Correct |
2 ms |
8920 KB |
Output is correct |
48 |
Correct |
3 ms |
8796 KB |
Output is correct |
49 |
Correct |
3 ms |
8824 KB |
Output is correct |
50 |
Correct |
2 ms |
8796 KB |
Output is correct |
51 |
Correct |
3 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 |
2 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 |
5 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8660 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8536 KB |
Output is correct |
11 |
Correct |
1 ms |
8660 KB |
Output is correct |
12 |
Correct |
1 ms |
8536 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
8540 KB |
Output is correct |
16 |
Correct |
2 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
4 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 |
2 ms |
8660 KB |
Output is correct |
26 |
Correct |
1 ms |
8536 KB |
Output is correct |
27 |
Correct |
1 ms |
8540 KB |
Output is correct |
28 |
Correct |
1 ms |
8540 KB |
Output is correct |
29 |
Correct |
3 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 |
8680 KB |
Output is correct |
35 |
Correct |
2 ms |
8536 KB |
Output is correct |
36 |
Correct |
1 ms |
8656 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 |
8792 KB |
Output is correct |
41 |
Correct |
3 ms |
8796 KB |
Output is correct |
42 |
Correct |
3 ms |
8796 KB |
Output is correct |
43 |
Correct |
2 ms |
8664 KB |
Output is correct |
44 |
Correct |
3 ms |
8792 KB |
Output is correct |
45 |
Correct |
3 ms |
8792 KB |
Output is correct |
46 |
Correct |
2 ms |
8796 KB |
Output is correct |
47 |
Correct |
2 ms |
8920 KB |
Output is correct |
48 |
Correct |
3 ms |
8796 KB |
Output is correct |
49 |
Correct |
3 ms |
8824 KB |
Output is correct |
50 |
Correct |
2 ms |
8796 KB |
Output is correct |
51 |
Correct |
3 ms |
8796 KB |
Output is correct |
52 |
Correct |
201 ms |
34132 KB |
Output is correct |
53 |
Correct |
143 ms |
34272 KB |
Output is correct |
54 |
Correct |
233 ms |
33308 KB |
Output is correct |
55 |
Correct |
212 ms |
33620 KB |
Output is correct |
56 |
Correct |
215 ms |
33876 KB |
Output is correct |
57 |
Correct |
218 ms |
33772 KB |
Output is correct |
58 |
Correct |
209 ms |
34128 KB |
Output is correct |
59 |
Correct |
218 ms |
33512 KB |
Output is correct |
60 |
Correct |
221 ms |
33308 KB |
Output is correct |
61 |
Correct |
216 ms |
33616 KB |
Output is correct |
62 |
Correct |
225 ms |
33692 KB |
Output is correct |
63 |
Correct |
132 ms |
32528 KB |
Output is correct |
64 |
Correct |
120 ms |
34388 KB |
Output is correct |
65 |
Correct |
157 ms |
34384 KB |
Output is correct |
66 |
Correct |
162 ms |
34188 KB |
Output is correct |
67 |
Correct |
140 ms |
34388 KB |
Output is correct |
68 |
Correct |
151 ms |
34352 KB |
Output is correct |
69 |
Correct |
192 ms |
34128 KB |
Output is correct |
70 |
Correct |
196 ms |
34076 KB |
Output is correct |
71 |
Correct |
193 ms |
33920 KB |
Output is correct |
72 |
Correct |
214 ms |
34428 KB |
Output is correct |
73 |
Correct |
199 ms |
34008 KB |
Output is correct |
74 |
Correct |
207 ms |
34140 KB |
Output is correct |
75 |
Correct |
217 ms |
34184 KB |
Output is correct |
76 |
Correct |
228 ms |
34160 KB |
Output is correct |
77 |
Correct |
191 ms |
33876 KB |
Output is correct |
78 |
Correct |
199 ms |
34172 KB |
Output is correct |
79 |
Correct |
193 ms |
33572 KB |
Output is correct |
80 |
Correct |
191 ms |
33492 KB |
Output is correct |