#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2e5;
const ll INF = 1e18;
struct Data
{
ll D, C;
bool operator < (const Data &p) { return D<p.D; }
};
int N, M;
ll X, W, T, S[MAXN+10], dp[MAXN+10], SC[MAXN+10];
Data A[MAXN+10];
vector<pll> V[MAXN+10];
struct Line { ll a, b; };
double cross(const Line &p, const Line &q) { return (double)(q.b-p.b)/(p.a-q.a); }
struct CHT
{
vector<Line> S;
void update(Line p)
{
while(S.size()>1 && cross(S[S.size()-1], p)<cross(S[S.size()-1], S[S.size()-2])) S.pop_back();
S.push_back(p);
}
ll query(ll x)
{
if(S.empty()) return INF;
int lo=0, hi=S.size();
while(lo+1<hi)
{
int mid=lo+hi>>1;
if(mid==0 || cross(S[mid], S[mid-1])<=x) lo=mid;
else hi=mid;
}
return S[lo].a*x+S[lo].b;
}
};
CHT tree[MAXN+10];
void update(int i, Line p)
{
i=M-i+1;
for(; i<=M+1; i+=(i&-i)) tree[i].update(p);
}
ll query(int i, ll x)
{
i=M-i+1; ll ret=INF;
for(; i>0; i-=(i&-i)) ret=min(ret, tree[i].query(x));
return ret;
}
int main()
{
int i, j;
scanf("%lld%d%d%lld%lld", &X, &N, &M, &W, &T);
for(i=1; i<=N; i++) scanf("%lld", &S[i]); S[N+1]=X;
for(i=1; i<=M; i++) scanf("%lld%lld", &A[i].D, &A[i].C);
sort(A+1, A+M+1);
sort(S+1, S+N+1);
for(i=1; i<=N+1; i++)
{
ll l, r;
if(S[i-1]/T==S[i]/T)
{
l=S[i-1]%T, r=S[i]%T;
l=lower_bound(A+1, A+M+1, (Data){l, 0})-A;
r=lower_bound(A+1, A+M+1, (Data){r, 0})-A-1;
}
else
{
l=0, r=S[i]%T;
l=lower_bound(A+1, A+M+1, (Data){l, 0})-A;
r=lower_bound(A+1, A+M+1, (Data){r, 0})-A-1;
}
if(l<=r) V[r].push_back({l, S[i]/T});
}
for(i=1; i<=M; i++) SC[i]=SC[i-1]+A[i].C;
dp[0]=(X/T+1)*W;
update(0, {0, dp[0]});
for(i=1; i<=M; i++)
{
if(A[i].D<=X%T) dp[i]=dp[i-1]+(X/T+1)*W;
else dp[i]=dp[i-1]+X/T*W;
for(auto it : V[i])
{
ll now=W*it.second*i+SC[i]+query(it.first-1, it.second);
dp[i]=min(dp[i], now);
}
update(i, {-W*i, dp[i]-SC[i]});
}
printf("%lld", dp[M]);
}
Compilation message
coach.cpp: In member function 'll CHT::query(ll)':
coach.cpp:39:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=lo+hi>>1;
~~^~~
coach.cpp: In function 'int main()':
coach.cpp:67:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(i=1; i<=N; i++) scanf("%lld", &S[i]); S[N+1]=X;
^~~
coach.cpp:67:44: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for(i=1; i<=N; i++) scanf("%lld", &S[i]); S[N+1]=X;
^
coach.cpp:64:9: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
coach.cpp:66:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%d%d%lld%lld", &X, &N, &M, &W, &T);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:67:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=N; i++) scanf("%lld", &S[i]); S[N+1]=X;
~~~~~^~~~~~~~~~~~~~~
coach.cpp:68:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=M; i++) scanf("%lld%lld", &A[i].D, &A[i].C);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9720 KB |
Output is correct |
2 |
Correct |
11 ms |
9720 KB |
Output is correct |
3 |
Correct |
11 ms |
9724 KB |
Output is correct |
4 |
Correct |
11 ms |
9724 KB |
Output is correct |
5 |
Correct |
11 ms |
9752 KB |
Output is correct |
6 |
Correct |
11 ms |
9720 KB |
Output is correct |
7 |
Correct |
11 ms |
9720 KB |
Output is correct |
8 |
Correct |
10 ms |
9724 KB |
Output is correct |
9 |
Correct |
10 ms |
9720 KB |
Output is correct |
10 |
Correct |
12 ms |
9720 KB |
Output is correct |
11 |
Correct |
11 ms |
9720 KB |
Output is correct |
12 |
Correct |
11 ms |
9720 KB |
Output is correct |
13 |
Correct |
12 ms |
9848 KB |
Output is correct |
14 |
Correct |
11 ms |
9720 KB |
Output is correct |
15 |
Correct |
10 ms |
9720 KB |
Output is correct |
16 |
Correct |
10 ms |
9720 KB |
Output is correct |
17 |
Correct |
11 ms |
9720 KB |
Output is correct |
18 |
Correct |
11 ms |
9720 KB |
Output is correct |
19 |
Correct |
12 ms |
9720 KB |
Output is correct |
20 |
Correct |
11 ms |
9720 KB |
Output is correct |
21 |
Correct |
11 ms |
9720 KB |
Output is correct |
22 |
Correct |
11 ms |
9720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9720 KB |
Output is correct |
2 |
Correct |
11 ms |
9720 KB |
Output is correct |
3 |
Correct |
11 ms |
9724 KB |
Output is correct |
4 |
Correct |
11 ms |
9724 KB |
Output is correct |
5 |
Correct |
11 ms |
9752 KB |
Output is correct |
6 |
Correct |
11 ms |
9720 KB |
Output is correct |
7 |
Correct |
11 ms |
9720 KB |
Output is correct |
8 |
Correct |
10 ms |
9724 KB |
Output is correct |
9 |
Correct |
10 ms |
9720 KB |
Output is correct |
10 |
Correct |
12 ms |
9720 KB |
Output is correct |
11 |
Correct |
11 ms |
9720 KB |
Output is correct |
12 |
Correct |
11 ms |
9720 KB |
Output is correct |
13 |
Correct |
12 ms |
9848 KB |
Output is correct |
14 |
Correct |
11 ms |
9720 KB |
Output is correct |
15 |
Correct |
10 ms |
9720 KB |
Output is correct |
16 |
Correct |
10 ms |
9720 KB |
Output is correct |
17 |
Correct |
11 ms |
9720 KB |
Output is correct |
18 |
Correct |
11 ms |
9720 KB |
Output is correct |
19 |
Correct |
12 ms |
9720 KB |
Output is correct |
20 |
Correct |
11 ms |
9720 KB |
Output is correct |
21 |
Correct |
11 ms |
9720 KB |
Output is correct |
22 |
Correct |
11 ms |
9720 KB |
Output is correct |
23 |
Correct |
10 ms |
9720 KB |
Output is correct |
24 |
Correct |
12 ms |
9848 KB |
Output is correct |
25 |
Correct |
13 ms |
9720 KB |
Output is correct |
26 |
Correct |
12 ms |
9724 KB |
Output is correct |
27 |
Correct |
13 ms |
9720 KB |
Output is correct |
28 |
Correct |
12 ms |
9720 KB |
Output is correct |
29 |
Correct |
11 ms |
9720 KB |
Output is correct |
30 |
Correct |
12 ms |
9720 KB |
Output is correct |
31 |
Correct |
12 ms |
9720 KB |
Output is correct |
32 |
Correct |
12 ms |
9720 KB |
Output is correct |
33 |
Correct |
11 ms |
9720 KB |
Output is correct |
34 |
Correct |
11 ms |
9720 KB |
Output is correct |
35 |
Correct |
13 ms |
9720 KB |
Output is correct |
36 |
Correct |
12 ms |
9720 KB |
Output is correct |
37 |
Correct |
11 ms |
9720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9720 KB |
Output is correct |
2 |
Correct |
11 ms |
9720 KB |
Output is correct |
3 |
Correct |
11 ms |
9724 KB |
Output is correct |
4 |
Correct |
11 ms |
9724 KB |
Output is correct |
5 |
Correct |
11 ms |
9752 KB |
Output is correct |
6 |
Correct |
11 ms |
9720 KB |
Output is correct |
7 |
Correct |
11 ms |
9720 KB |
Output is correct |
8 |
Correct |
10 ms |
9724 KB |
Output is correct |
9 |
Correct |
10 ms |
9720 KB |
Output is correct |
10 |
Correct |
12 ms |
9720 KB |
Output is correct |
11 |
Correct |
11 ms |
9720 KB |
Output is correct |
12 |
Correct |
11 ms |
9720 KB |
Output is correct |
13 |
Correct |
12 ms |
9848 KB |
Output is correct |
14 |
Correct |
11 ms |
9720 KB |
Output is correct |
15 |
Correct |
10 ms |
9720 KB |
Output is correct |
16 |
Correct |
10 ms |
9720 KB |
Output is correct |
17 |
Correct |
11 ms |
9720 KB |
Output is correct |
18 |
Correct |
11 ms |
9720 KB |
Output is correct |
19 |
Correct |
12 ms |
9720 KB |
Output is correct |
20 |
Correct |
11 ms |
9720 KB |
Output is correct |
21 |
Correct |
11 ms |
9720 KB |
Output is correct |
22 |
Correct |
11 ms |
9720 KB |
Output is correct |
23 |
Correct |
10 ms |
9720 KB |
Output is correct |
24 |
Correct |
12 ms |
9848 KB |
Output is correct |
25 |
Correct |
13 ms |
9720 KB |
Output is correct |
26 |
Correct |
12 ms |
9724 KB |
Output is correct |
27 |
Correct |
13 ms |
9720 KB |
Output is correct |
28 |
Correct |
12 ms |
9720 KB |
Output is correct |
29 |
Correct |
11 ms |
9720 KB |
Output is correct |
30 |
Correct |
12 ms |
9720 KB |
Output is correct |
31 |
Correct |
12 ms |
9720 KB |
Output is correct |
32 |
Correct |
12 ms |
9720 KB |
Output is correct |
33 |
Correct |
11 ms |
9720 KB |
Output is correct |
34 |
Correct |
11 ms |
9720 KB |
Output is correct |
35 |
Correct |
13 ms |
9720 KB |
Output is correct |
36 |
Correct |
12 ms |
9720 KB |
Output is correct |
37 |
Correct |
11 ms |
9720 KB |
Output is correct |
38 |
Correct |
13 ms |
9976 KB |
Output is correct |
39 |
Correct |
13 ms |
9976 KB |
Output is correct |
40 |
Correct |
15 ms |
9976 KB |
Output is correct |
41 |
Correct |
14 ms |
9976 KB |
Output is correct |
42 |
Correct |
14 ms |
9976 KB |
Output is correct |
43 |
Correct |
13 ms |
9976 KB |
Output is correct |
44 |
Correct |
14 ms |
9976 KB |
Output is correct |
45 |
Correct |
13 ms |
9976 KB |
Output is correct |
46 |
Correct |
13 ms |
10108 KB |
Output is correct |
47 |
Correct |
13 ms |
9980 KB |
Output is correct |
48 |
Correct |
14 ms |
9976 KB |
Output is correct |
49 |
Correct |
13 ms |
9980 KB |
Output is correct |
50 |
Correct |
14 ms |
9976 KB |
Output is correct |
51 |
Correct |
14 ms |
9976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9720 KB |
Output is correct |
2 |
Correct |
11 ms |
9720 KB |
Output is correct |
3 |
Correct |
11 ms |
9724 KB |
Output is correct |
4 |
Correct |
11 ms |
9724 KB |
Output is correct |
5 |
Correct |
11 ms |
9752 KB |
Output is correct |
6 |
Correct |
11 ms |
9720 KB |
Output is correct |
7 |
Correct |
11 ms |
9720 KB |
Output is correct |
8 |
Correct |
10 ms |
9724 KB |
Output is correct |
9 |
Correct |
10 ms |
9720 KB |
Output is correct |
10 |
Correct |
12 ms |
9720 KB |
Output is correct |
11 |
Correct |
11 ms |
9720 KB |
Output is correct |
12 |
Correct |
11 ms |
9720 KB |
Output is correct |
13 |
Correct |
12 ms |
9848 KB |
Output is correct |
14 |
Correct |
11 ms |
9720 KB |
Output is correct |
15 |
Correct |
10 ms |
9720 KB |
Output is correct |
16 |
Correct |
10 ms |
9720 KB |
Output is correct |
17 |
Correct |
11 ms |
9720 KB |
Output is correct |
18 |
Correct |
11 ms |
9720 KB |
Output is correct |
19 |
Correct |
12 ms |
9720 KB |
Output is correct |
20 |
Correct |
11 ms |
9720 KB |
Output is correct |
21 |
Correct |
11 ms |
9720 KB |
Output is correct |
22 |
Correct |
11 ms |
9720 KB |
Output is correct |
23 |
Correct |
10 ms |
9720 KB |
Output is correct |
24 |
Correct |
12 ms |
9848 KB |
Output is correct |
25 |
Correct |
13 ms |
9720 KB |
Output is correct |
26 |
Correct |
12 ms |
9724 KB |
Output is correct |
27 |
Correct |
13 ms |
9720 KB |
Output is correct |
28 |
Correct |
12 ms |
9720 KB |
Output is correct |
29 |
Correct |
11 ms |
9720 KB |
Output is correct |
30 |
Correct |
12 ms |
9720 KB |
Output is correct |
31 |
Correct |
12 ms |
9720 KB |
Output is correct |
32 |
Correct |
12 ms |
9720 KB |
Output is correct |
33 |
Correct |
11 ms |
9720 KB |
Output is correct |
34 |
Correct |
11 ms |
9720 KB |
Output is correct |
35 |
Correct |
13 ms |
9720 KB |
Output is correct |
36 |
Correct |
12 ms |
9720 KB |
Output is correct |
37 |
Correct |
11 ms |
9720 KB |
Output is correct |
38 |
Correct |
13 ms |
9976 KB |
Output is correct |
39 |
Correct |
13 ms |
9976 KB |
Output is correct |
40 |
Correct |
15 ms |
9976 KB |
Output is correct |
41 |
Correct |
14 ms |
9976 KB |
Output is correct |
42 |
Correct |
14 ms |
9976 KB |
Output is correct |
43 |
Correct |
13 ms |
9976 KB |
Output is correct |
44 |
Correct |
14 ms |
9976 KB |
Output is correct |
45 |
Correct |
13 ms |
9976 KB |
Output is correct |
46 |
Correct |
13 ms |
10108 KB |
Output is correct |
47 |
Correct |
13 ms |
9980 KB |
Output is correct |
48 |
Correct |
14 ms |
9976 KB |
Output is correct |
49 |
Correct |
13 ms |
9980 KB |
Output is correct |
50 |
Correct |
14 ms |
9976 KB |
Output is correct |
51 |
Correct |
14 ms |
9976 KB |
Output is correct |
52 |
Correct |
399 ms |
33384 KB |
Output is correct |
53 |
Correct |
368 ms |
40384 KB |
Output is correct |
54 |
Correct |
258 ms |
41796 KB |
Output is correct |
55 |
Correct |
257 ms |
38896 KB |
Output is correct |
56 |
Correct |
252 ms |
35832 KB |
Output is correct |
57 |
Correct |
262 ms |
38392 KB |
Output is correct |
58 |
Correct |
242 ms |
35832 KB |
Output is correct |
59 |
Correct |
260 ms |
38768 KB |
Output is correct |
60 |
Correct |
263 ms |
41076 KB |
Output is correct |
61 |
Correct |
259 ms |
39632 KB |
Output is correct |
62 |
Correct |
269 ms |
39152 KB |
Output is correct |
63 |
Correct |
250 ms |
60184 KB |
Output is correct |
64 |
Correct |
207 ms |
33656 KB |
Output is correct |
65 |
Correct |
357 ms |
39928 KB |
Output is correct |
66 |
Correct |
360 ms |
39912 KB |
Output is correct |
67 |
Correct |
379 ms |
40056 KB |
Output is correct |
68 |
Correct |
376 ms |
40292 KB |
Output is correct |
69 |
Correct |
403 ms |
39040 KB |
Output is correct |
70 |
Correct |
398 ms |
38964 KB |
Output is correct |
71 |
Correct |
443 ms |
38904 KB |
Output is correct |
72 |
Correct |
405 ms |
38908 KB |
Output is correct |
73 |
Correct |
402 ms |
38876 KB |
Output is correct |
74 |
Correct |
380 ms |
38776 KB |
Output is correct |
75 |
Correct |
399 ms |
38520 KB |
Output is correct |
76 |
Correct |
400 ms |
38732 KB |
Output is correct |
77 |
Correct |
274 ms |
50668 KB |
Output is correct |
78 |
Correct |
251 ms |
36856 KB |
Output is correct |
79 |
Correct |
394 ms |
38648 KB |
Output is correct |
80 |
Correct |
396 ms |
38648 KB |
Output is correct |