#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long lo;
typedef __int128 ll;
typedef pair<ll,ll> pll;
struct wat {
ll q, r, loc;
bool operator < (const wat &A) const {return loc<A.loc;}
};
ll ccw(const pll &a,const pll &b,const pll &c) {return a.x*b.y+b.x*c.y+c.x*a.y-a.y*b.x-b.y*c.x-c.y*a.x;}
pll operator * (const pll &a, const pll &b) {return pll(a.second-b.second,b.first-a.first);}
bool operator < (const pll &a, const pll &b) {return a.first*b.second<b.first*a.second;}
struct CHT {
vector<pll> vec;
void add(ll x, ll y) {
pll tmp = pll(x,y);
while(!vec.empty()&&vec.back().first>x) vec.pop_back();
while(vec.size()>=2&&ccw(vec[vec.size()-2],vec.back(),tmp)>=0) vec.pop_back();
if (!vec.empty()&&vec.back().first==x) {
if (vec.back().second<=y) vec.pop_back();
else return;
}
vec.push_back(tmp);
}
ll getv(ll x) {
pll tmp = pll(x,1);
int s = 0, e = (int)vec.size()-2;
while(s<=e) {
int m = (s+e)>>1;
if (tmp<vec[m]*vec[m+1]) e = m-1;
else s = m+1;
}
return vec[s].first*x+vec[s].second;
}
} cht;
ll x, n, m, w, t, res;
wat S[200100];
pll DC[200100];
ll ps[200100];
ll dp[200100];
int main() {
int i;
lo tx, tn, tm, tw, tt;
scanf("%lld%lld%lld%lld%lld",&tx,&tn,&tm,&tw,&tt); ++tn;
x=tx;n=tn;m=tm;w=tw;t=tt;
for (i=0;i<n;i++) {
lo ta; ll a;
if (i!=n-1) {scanf("%lld",&ta); a=ta;}
else a = x;
S[i].q = w*(a/t); S[i].r = a%t;
}
for (i=0;i<m;i++) {
lo x, y;
scanf("%lld%lld",&x,&y);
DC[i] = pll(x,y);
}
m++; DC[m-1] = pll(0,0);
sort(DC,DC+m);
for (i=0;i<n;i++) S[i].loc = upper_bound(DC,DC+m,pll(S[i].r,0))-DC;
for (i=m-1;i>=0;i--) {
ll cnt = (DC[i].first<x%t)?x/t+1:x/t;
ps[i] = ps[i+1] + w*cnt-DC[i].second;
res += w*cnt;
}
sort(S,S+n);
int j; i = n-1;
for (j=m-1;j>=0;j--) {
while(i>=0&&S[i].loc>j) {
cht.add(S[i].q,dp[S[i].loc]-ps[S[i].loc]-S[i].loc*S[i].q);
i--;
}
dp[j] = max((i==n-1)?0:cht.getv(j)+ps[j],dp[j+1]);
}
printf("%lld\n",(lo)(res-dp[1]));
return 0;
}
Compilation message
coach.cpp: In function 'int main()':
coach.cpp:53:51: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld%lld%lld",&tx,&tn,&tm,&tw,&tt); ++tn;
^
coach.cpp:57:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
if (i!=n-1) {scanf("%lld",&ta); a=ta;}
^
coach.cpp:63:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld",&x,&y);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
23912 KB |
Output is correct |
2 |
Correct |
0 ms |
23912 KB |
Output is correct |
3 |
Correct |
0 ms |
23912 KB |
Output is correct |
4 |
Correct |
0 ms |
23912 KB |
Output is correct |
5 |
Correct |
0 ms |
23912 KB |
Output is correct |
6 |
Correct |
0 ms |
23912 KB |
Output is correct |
7 |
Correct |
0 ms |
23912 KB |
Output is correct |
8 |
Correct |
0 ms |
23912 KB |
Output is correct |
9 |
Correct |
0 ms |
23912 KB |
Output is correct |
10 |
Correct |
0 ms |
23912 KB |
Output is correct |
11 |
Correct |
0 ms |
23912 KB |
Output is correct |
12 |
Correct |
0 ms |
23912 KB |
Output is correct |
13 |
Correct |
0 ms |
23912 KB |
Output is correct |
14 |
Correct |
0 ms |
23912 KB |
Output is correct |
15 |
Correct |
0 ms |
23912 KB |
Output is correct |
16 |
Correct |
0 ms |
23912 KB |
Output is correct |
17 |
Correct |
0 ms |
23912 KB |
Output is correct |
18 |
Correct |
0 ms |
23912 KB |
Output is correct |
19 |
Correct |
0 ms |
23912 KB |
Output is correct |
20 |
Correct |
0 ms |
23912 KB |
Output is correct |
21 |
Correct |
0 ms |
23912 KB |
Output is correct |
22 |
Correct |
0 ms |
23912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
23912 KB |
Output is correct |
2 |
Correct |
0 ms |
23912 KB |
Output is correct |
3 |
Correct |
0 ms |
23912 KB |
Output is correct |
4 |
Correct |
0 ms |
23912 KB |
Output is correct |
5 |
Correct |
0 ms |
23912 KB |
Output is correct |
6 |
Correct |
0 ms |
23912 KB |
Output is correct |
7 |
Correct |
0 ms |
23912 KB |
Output is correct |
8 |
Correct |
0 ms |
23912 KB |
Output is correct |
9 |
Correct |
0 ms |
23912 KB |
Output is correct |
10 |
Correct |
0 ms |
23912 KB |
Output is correct |
11 |
Correct |
0 ms |
23912 KB |
Output is correct |
12 |
Correct |
0 ms |
23912 KB |
Output is correct |
13 |
Correct |
0 ms |
23912 KB |
Output is correct |
14 |
Correct |
0 ms |
23912 KB |
Output is correct |
15 |
Correct |
0 ms |
23912 KB |
Output is correct |
16 |
Correct |
0 ms |
23912 KB |
Output is correct |
17 |
Correct |
0 ms |
23912 KB |
Output is correct |
18 |
Correct |
0 ms |
23912 KB |
Output is correct |
19 |
Correct |
0 ms |
23912 KB |
Output is correct |
20 |
Correct |
0 ms |
23912 KB |
Output is correct |
21 |
Correct |
0 ms |
23912 KB |
Output is correct |
22 |
Correct |
0 ms |
23912 KB |
Output is correct |
23 |
Correct |
0 ms |
23912 KB |
Output is correct |
24 |
Correct |
0 ms |
23912 KB |
Output is correct |
25 |
Correct |
0 ms |
23912 KB |
Output is correct |
26 |
Correct |
0 ms |
23912 KB |
Output is correct |
27 |
Correct |
0 ms |
23912 KB |
Output is correct |
28 |
Correct |
0 ms |
23912 KB |
Output is correct |
29 |
Correct |
0 ms |
23912 KB |
Output is correct |
30 |
Correct |
0 ms |
23912 KB |
Output is correct |
31 |
Correct |
0 ms |
23912 KB |
Output is correct |
32 |
Correct |
0 ms |
23912 KB |
Output is correct |
33 |
Correct |
0 ms |
23912 KB |
Output is correct |
34 |
Correct |
0 ms |
23912 KB |
Output is correct |
35 |
Correct |
0 ms |
23912 KB |
Output is correct |
36 |
Correct |
0 ms |
23912 KB |
Output is correct |
37 |
Correct |
0 ms |
23912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
23912 KB |
Output is correct |
2 |
Correct |
0 ms |
23912 KB |
Output is correct |
3 |
Correct |
0 ms |
23912 KB |
Output is correct |
4 |
Correct |
0 ms |
23912 KB |
Output is correct |
5 |
Correct |
0 ms |
23912 KB |
Output is correct |
6 |
Correct |
0 ms |
23912 KB |
Output is correct |
7 |
Correct |
0 ms |
23912 KB |
Output is correct |
8 |
Correct |
0 ms |
23912 KB |
Output is correct |
9 |
Correct |
0 ms |
23912 KB |
Output is correct |
10 |
Correct |
0 ms |
23912 KB |
Output is correct |
11 |
Correct |
0 ms |
23912 KB |
Output is correct |
12 |
Correct |
0 ms |
23912 KB |
Output is correct |
13 |
Correct |
0 ms |
23912 KB |
Output is correct |
14 |
Correct |
0 ms |
23912 KB |
Output is correct |
15 |
Correct |
0 ms |
23912 KB |
Output is correct |
16 |
Correct |
0 ms |
23912 KB |
Output is correct |
17 |
Correct |
0 ms |
23912 KB |
Output is correct |
18 |
Correct |
0 ms |
23912 KB |
Output is correct |
19 |
Correct |
0 ms |
23912 KB |
Output is correct |
20 |
Correct |
0 ms |
23912 KB |
Output is correct |
21 |
Correct |
0 ms |
23912 KB |
Output is correct |
22 |
Correct |
0 ms |
23912 KB |
Output is correct |
23 |
Correct |
0 ms |
23912 KB |
Output is correct |
24 |
Correct |
0 ms |
23912 KB |
Output is correct |
25 |
Correct |
0 ms |
23912 KB |
Output is correct |
26 |
Correct |
0 ms |
23912 KB |
Output is correct |
27 |
Correct |
0 ms |
23912 KB |
Output is correct |
28 |
Correct |
0 ms |
23912 KB |
Output is correct |
29 |
Correct |
0 ms |
23912 KB |
Output is correct |
30 |
Correct |
0 ms |
23912 KB |
Output is correct |
31 |
Correct |
0 ms |
23912 KB |
Output is correct |
32 |
Correct |
0 ms |
23912 KB |
Output is correct |
33 |
Correct |
0 ms |
23912 KB |
Output is correct |
34 |
Correct |
0 ms |
23912 KB |
Output is correct |
35 |
Correct |
0 ms |
23912 KB |
Output is correct |
36 |
Correct |
0 ms |
23912 KB |
Output is correct |
37 |
Correct |
0 ms |
23912 KB |
Output is correct |
38 |
Correct |
0 ms |
23912 KB |
Output is correct |
39 |
Correct |
3 ms |
23912 KB |
Output is correct |
40 |
Correct |
3 ms |
23912 KB |
Output is correct |
41 |
Correct |
0 ms |
23912 KB |
Output is correct |
42 |
Correct |
3 ms |
23912 KB |
Output is correct |
43 |
Correct |
0 ms |
23912 KB |
Output is correct |
44 |
Correct |
0 ms |
23912 KB |
Output is correct |
45 |
Correct |
0 ms |
23912 KB |
Output is correct |
46 |
Correct |
0 ms |
23912 KB |
Output is correct |
47 |
Correct |
0 ms |
23912 KB |
Output is correct |
48 |
Correct |
3 ms |
23912 KB |
Output is correct |
49 |
Correct |
0 ms |
23912 KB |
Output is correct |
50 |
Correct |
0 ms |
23912 KB |
Output is correct |
51 |
Correct |
0 ms |
23912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
23912 KB |
Output is correct |
2 |
Correct |
0 ms |
23912 KB |
Output is correct |
3 |
Correct |
0 ms |
23912 KB |
Output is correct |
4 |
Correct |
0 ms |
23912 KB |
Output is correct |
5 |
Correct |
0 ms |
23912 KB |
Output is correct |
6 |
Correct |
0 ms |
23912 KB |
Output is correct |
7 |
Correct |
0 ms |
23912 KB |
Output is correct |
8 |
Correct |
0 ms |
23912 KB |
Output is correct |
9 |
Correct |
0 ms |
23912 KB |
Output is correct |
10 |
Correct |
0 ms |
23912 KB |
Output is correct |
11 |
Correct |
0 ms |
23912 KB |
Output is correct |
12 |
Correct |
0 ms |
23912 KB |
Output is correct |
13 |
Correct |
0 ms |
23912 KB |
Output is correct |
14 |
Correct |
0 ms |
23912 KB |
Output is correct |
15 |
Correct |
0 ms |
23912 KB |
Output is correct |
16 |
Correct |
0 ms |
23912 KB |
Output is correct |
17 |
Correct |
0 ms |
23912 KB |
Output is correct |
18 |
Correct |
0 ms |
23912 KB |
Output is correct |
19 |
Correct |
0 ms |
23912 KB |
Output is correct |
20 |
Correct |
0 ms |
23912 KB |
Output is correct |
21 |
Correct |
0 ms |
23912 KB |
Output is correct |
22 |
Correct |
0 ms |
23912 KB |
Output is correct |
23 |
Correct |
0 ms |
23912 KB |
Output is correct |
24 |
Correct |
0 ms |
23912 KB |
Output is correct |
25 |
Correct |
0 ms |
23912 KB |
Output is correct |
26 |
Correct |
0 ms |
23912 KB |
Output is correct |
27 |
Correct |
0 ms |
23912 KB |
Output is correct |
28 |
Correct |
0 ms |
23912 KB |
Output is correct |
29 |
Correct |
0 ms |
23912 KB |
Output is correct |
30 |
Correct |
0 ms |
23912 KB |
Output is correct |
31 |
Correct |
0 ms |
23912 KB |
Output is correct |
32 |
Correct |
0 ms |
23912 KB |
Output is correct |
33 |
Correct |
0 ms |
23912 KB |
Output is correct |
34 |
Correct |
0 ms |
23912 KB |
Output is correct |
35 |
Correct |
0 ms |
23912 KB |
Output is correct |
36 |
Correct |
0 ms |
23912 KB |
Output is correct |
37 |
Correct |
0 ms |
23912 KB |
Output is correct |
38 |
Correct |
0 ms |
23912 KB |
Output is correct |
39 |
Correct |
3 ms |
23912 KB |
Output is correct |
40 |
Correct |
3 ms |
23912 KB |
Output is correct |
41 |
Correct |
0 ms |
23912 KB |
Output is correct |
42 |
Correct |
3 ms |
23912 KB |
Output is correct |
43 |
Correct |
0 ms |
23912 KB |
Output is correct |
44 |
Correct |
0 ms |
23912 KB |
Output is correct |
45 |
Correct |
0 ms |
23912 KB |
Output is correct |
46 |
Correct |
0 ms |
23912 KB |
Output is correct |
47 |
Correct |
0 ms |
23912 KB |
Output is correct |
48 |
Correct |
3 ms |
23912 KB |
Output is correct |
49 |
Correct |
0 ms |
23912 KB |
Output is correct |
50 |
Correct |
0 ms |
23912 KB |
Output is correct |
51 |
Correct |
0 ms |
23912 KB |
Output is correct |
52 |
Correct |
229 ms |
23912 KB |
Output is correct |
53 |
Correct |
199 ms |
23912 KB |
Output is correct |
54 |
Correct |
246 ms |
23912 KB |
Output is correct |
55 |
Correct |
279 ms |
23912 KB |
Output is correct |
56 |
Correct |
249 ms |
23912 KB |
Output is correct |
57 |
Correct |
313 ms |
23912 KB |
Output is correct |
58 |
Correct |
259 ms |
23912 KB |
Output is correct |
59 |
Correct |
276 ms |
23912 KB |
Output is correct |
60 |
Correct |
269 ms |
23912 KB |
Output is correct |
61 |
Correct |
243 ms |
23912 KB |
Output is correct |
62 |
Correct |
249 ms |
23912 KB |
Output is correct |
63 |
Correct |
169 ms |
23912 KB |
Output is correct |
64 |
Correct |
206 ms |
23912 KB |
Output is correct |
65 |
Correct |
223 ms |
23912 KB |
Output is correct |
66 |
Correct |
276 ms |
23912 KB |
Output is correct |
67 |
Correct |
259 ms |
23912 KB |
Output is correct |
68 |
Correct |
256 ms |
23912 KB |
Output is correct |
69 |
Correct |
239 ms |
23912 KB |
Output is correct |
70 |
Correct |
266 ms |
23912 KB |
Output is correct |
71 |
Correct |
243 ms |
23912 KB |
Output is correct |
72 |
Correct |
266 ms |
23912 KB |
Output is correct |
73 |
Correct |
269 ms |
23912 KB |
Output is correct |
74 |
Correct |
273 ms |
23912 KB |
Output is correct |
75 |
Correct |
256 ms |
23912 KB |
Output is correct |
76 |
Correct |
296 ms |
23912 KB |
Output is correct |
77 |
Correct |
249 ms |
23912 KB |
Output is correct |
78 |
Correct |
233 ms |
23912 KB |
Output is correct |
79 |
Correct |
219 ms |
23912 KB |
Output is correct |
80 |
Correct |
239 ms |
23912 KB |
Output is correct |