#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifdef TEST
typedef long long BigInt;
#else
typedef __int128 BigInt;
#endif // TEST
struct Person{
ll off, cost;
Person(){}
Person(ll off, ll cost): off(off), cost(cost){}
bool operator<(const Person &r)const{
return off < r.off;
}
};
struct Query{
int st;
ll constant, slope;
Query(int st, ll constant, ll slope): st(st), constant(constant), slope(slope){}
};
ll X, W, T;
int n, k;
ll arr[200002];
Person person[200002];
ll DP[200002], adj[200002], costSum[200002];
ll ans = 9e18;
vector<Query> queryVec[200002];
vector<pair<int, ll> > convexHull;
bool better(int l, int r, ll slope){
BigInt A = -BigInt(slope) * BigInt(convexHull[l].first) + convexHull[l].second;
BigInt B = -BigInt(slope) * BigInt(convexHull[r].first) + convexHull[r].second;
return A<=B;
}
ll findVal(int s, int e, ll slope){
int l = lower_bound(convexHull.begin(), convexHull.end(), make_pair(s, LLONG_MIN)) - convexHull.begin();
int r = (int)convexHull.size()-1;
while(r-l>=3){
int m = (l+r)/2;
if(better(m, m+1, slope)) r = m+1;
else l = m;
}
ll ret = LLONG_MAX;
for(int i=l; i<=r; i++) ret = min(ret, convexHull[i].second - convexHull[i].first * slope);
return ret;
}
long double calcSlope(pair<int, ll> p1, pair<int, ll> p2){
return (long double)(p2.second - p1.second) / (p2.first - p1.first);
}
bool canInsert(BigInt x, BigInt y){
BigInt a = convexHull[convexHull.size()-2].first, b = convexHull[convexHull.size()-2].second;
BigInt c = convexHull.back().first, d = convexHull.back().second;
return (c-a)*(y-b) - (d-b)*(x-a) > 0;
}
void updatePoint(ll x, ll y){
while(convexHull.size() >= 2 && !canInsert(x, y)){
convexHull.pop_back();
}
convexHull.push_back(make_pair(x, y));
}
int main(){
scanf("%lld %d %d %lld %lld", &X, &k, &n, &W, &T);
for(int i=1; i<=k; i++) scanf("%lld", &arr[i]);
sort(arr+1, arr+k+1);
arr[++k] = X;
for(int i=1; i<=n; i++) scanf("%lld %lld", &person[i].off, &person[i].cost);
sort(person+1, person+n+1);
DP[0] = (X / T + 1) * W;
for(int i=1; i<=n; i++){
DP[i] = 9e18;
costSum[i] = costSum[i-1] + person[i].cost;
adj[i] = -costSum[i];
}
for(int i=1; i<=k; i++){
ll prv = arr[i-1], now = arr[i];
int st = 1, en = lower_bound(person+1, person+n+1, Person(now%T, 0)) - person - 1;
if(prv%T == now%T) st = upper_bound(person+1, person+n+1, Person(prv%T, 0)) - person;
if(st > en) continue;
ll slope = now/T*W;
queryVec[en].push_back(Query(st-1, costSum[en] + slope*en, slope));
}
convexHull.push_back(make_pair(0, DP[0]));
for(int i=1; i<=n; i++){
DP[i] = DP[i-1] + ((X - person[i].off + T) / T * W);
for(Query query: queryVec[i]){
ll tmp = findVal(query.st, i-1, query.slope);
DP[i] = min(DP[i], tmp + query.constant);
}
updatePoint(i, DP[i] + adj[i]);
}
printf("%lld", DP[n]);
}
Compilation message
coach.cpp: In function 'int main()':
coach.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | scanf("%lld %d %d %lld %lld", &X, &k, &n, &W, &T);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:74:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | for(int i=1; i<=k; i++) scanf("%lld", &arr[i]);
| ~~~~~^~~~~~~~~~~~~~~~~
coach.cpp:77:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
77 | for(int i=1; i<=n; i++) scanf("%lld %lld", &person[i].off, &person[i].cost);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
4 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
4 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
2 ms |
4948 KB |
Output is correct |
24 |
Correct |
2 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4948 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
2 ms |
4948 KB |
Output is correct |
28 |
Correct |
2 ms |
4948 KB |
Output is correct |
29 |
Correct |
2 ms |
4948 KB |
Output is correct |
30 |
Correct |
3 ms |
4948 KB |
Output is correct |
31 |
Correct |
2 ms |
4948 KB |
Output is correct |
32 |
Correct |
2 ms |
4948 KB |
Output is correct |
33 |
Correct |
4 ms |
5040 KB |
Output is correct |
34 |
Correct |
2 ms |
4948 KB |
Output is correct |
35 |
Correct |
3 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
4 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
2 ms |
4948 KB |
Output is correct |
24 |
Correct |
2 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4948 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
2 ms |
4948 KB |
Output is correct |
28 |
Correct |
2 ms |
4948 KB |
Output is correct |
29 |
Correct |
2 ms |
4948 KB |
Output is correct |
30 |
Correct |
3 ms |
4948 KB |
Output is correct |
31 |
Correct |
2 ms |
4948 KB |
Output is correct |
32 |
Correct |
2 ms |
4948 KB |
Output is correct |
33 |
Correct |
4 ms |
5040 KB |
Output is correct |
34 |
Correct |
2 ms |
4948 KB |
Output is correct |
35 |
Correct |
3 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
38 |
Correct |
4 ms |
5200 KB |
Output is correct |
39 |
Correct |
4 ms |
5076 KB |
Output is correct |
40 |
Correct |
4 ms |
5076 KB |
Output is correct |
41 |
Correct |
4 ms |
5076 KB |
Output is correct |
42 |
Correct |
4 ms |
5076 KB |
Output is correct |
43 |
Correct |
4 ms |
5144 KB |
Output is correct |
44 |
Correct |
5 ms |
5076 KB |
Output is correct |
45 |
Correct |
4 ms |
5076 KB |
Output is correct |
46 |
Correct |
4 ms |
5204 KB |
Output is correct |
47 |
Correct |
3 ms |
5076 KB |
Output is correct |
48 |
Correct |
4 ms |
5076 KB |
Output is correct |
49 |
Correct |
4 ms |
5076 KB |
Output is correct |
50 |
Correct |
4 ms |
5076 KB |
Output is correct |
51 |
Correct |
4 ms |
5076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
4 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
2 ms |
4948 KB |
Output is correct |
24 |
Correct |
2 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4948 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
2 ms |
4948 KB |
Output is correct |
28 |
Correct |
2 ms |
4948 KB |
Output is correct |
29 |
Correct |
2 ms |
4948 KB |
Output is correct |
30 |
Correct |
3 ms |
4948 KB |
Output is correct |
31 |
Correct |
2 ms |
4948 KB |
Output is correct |
32 |
Correct |
2 ms |
4948 KB |
Output is correct |
33 |
Correct |
4 ms |
5040 KB |
Output is correct |
34 |
Correct |
2 ms |
4948 KB |
Output is correct |
35 |
Correct |
3 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
38 |
Correct |
4 ms |
5200 KB |
Output is correct |
39 |
Correct |
4 ms |
5076 KB |
Output is correct |
40 |
Correct |
4 ms |
5076 KB |
Output is correct |
41 |
Correct |
4 ms |
5076 KB |
Output is correct |
42 |
Correct |
4 ms |
5076 KB |
Output is correct |
43 |
Correct |
4 ms |
5144 KB |
Output is correct |
44 |
Correct |
5 ms |
5076 KB |
Output is correct |
45 |
Correct |
4 ms |
5076 KB |
Output is correct |
46 |
Correct |
4 ms |
5204 KB |
Output is correct |
47 |
Correct |
3 ms |
5076 KB |
Output is correct |
48 |
Correct |
4 ms |
5076 KB |
Output is correct |
49 |
Correct |
4 ms |
5076 KB |
Output is correct |
50 |
Correct |
4 ms |
5076 KB |
Output is correct |
51 |
Correct |
4 ms |
5076 KB |
Output is correct |
52 |
Correct |
192 ms |
20876 KB |
Output is correct |
53 |
Correct |
185 ms |
20520 KB |
Output is correct |
54 |
Correct |
121 ms |
20876 KB |
Output is correct |
55 |
Correct |
129 ms |
20776 KB |
Output is correct |
56 |
Correct |
129 ms |
20936 KB |
Output is correct |
57 |
Correct |
133 ms |
20884 KB |
Output is correct |
58 |
Correct |
125 ms |
20884 KB |
Output is correct |
59 |
Correct |
129 ms |
20900 KB |
Output is correct |
60 |
Correct |
123 ms |
20888 KB |
Output is correct |
61 |
Correct |
124 ms |
20856 KB |
Output is correct |
62 |
Correct |
124 ms |
20904 KB |
Output is correct |
63 |
Correct |
120 ms |
24836 KB |
Output is correct |
64 |
Correct |
123 ms |
18460 KB |
Output is correct |
65 |
Correct |
171 ms |
24704 KB |
Output is correct |
66 |
Correct |
177 ms |
24796 KB |
Output is correct |
67 |
Correct |
201 ms |
24832 KB |
Output is correct |
68 |
Correct |
170 ms |
24776 KB |
Output is correct |
69 |
Correct |
211 ms |
24948 KB |
Output is correct |
70 |
Correct |
211 ms |
25000 KB |
Output is correct |
71 |
Correct |
194 ms |
25048 KB |
Output is correct |
72 |
Correct |
190 ms |
25008 KB |
Output is correct |
73 |
Correct |
198 ms |
25144 KB |
Output is correct |
74 |
Correct |
217 ms |
24976 KB |
Output is correct |
75 |
Correct |
188 ms |
24900 KB |
Output is correct |
76 |
Correct |
216 ms |
25020 KB |
Output is correct |
77 |
Correct |
141 ms |
25020 KB |
Output is correct |
78 |
Correct |
155 ms |
25064 KB |
Output is correct |
79 |
Correct |
214 ms |
25032 KB |
Output is correct |
80 |
Correct |
184 ms |
25144 KB |
Output is correct |