#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
int main(){
cin.sync_with_stdio(0); cin.tie(0);
LL X, N, M, W, T;
cin >> X >> N >> M >> W >> T;
T *= 2;
X *= 2;
// X = total duration
// N = # stops
// M = # passenges
vector<LL> stop;
stop.push_back(0);
for(LL i = 0; i < N; i++){
LL s;
cin >> s;
s *= 2;
stop.push_back(s);
}
stop.push_back(X);
// W = cost
vector<pair<LL,LL> > times;
LL totalrefundcost = 0;
for(LL i = 0; i < M; i++){
LL d, c;
cin >> d >> c;
d *= 2;
totalrefundcost += c;
if(X < (X/T) * T + d){
c += W;
stop.push_back((X/T) * T + d + 1);
}
times.push_back({d,c});
}
sort(times.begin(), times.end());
sort(stop.begin(), stop.end());
X = ((X/T) + 1) * T;
vector<LL> t;
vector<LL> refundcost;
t.push_back(0);
refundcost.push_back(0); // but you must always feed the driver
for(int i = 0; i < times.size(); i++){
t.push_back(times[i].first);
refundcost.push_back(times[i].second);
}
t.push_back(T);
refundcost.push_back(0); // should not use this result
vector<LL> dp(refundcost.size(), W*(X+1));
dp[0] = 0;
LL rounds = W * (X/T);
vector<LL> mincost(refundcost.size(), rounds);
for(LL r = 1; r < stop.size(); r++){
LL R = stop[r];
for(int i = 0; i < t.size(); i++){
if(t[i] < (R % T) && (R % T) < t[i+1]){
mincost[i] = min(mincost[i], W * (stop[r] / T));
break;
}
}
}
for(int j = 1; j < refundcost.size(); j++){
LL cost = 0;
LL curcost = rounds;
for(int i = j-1; i >= 0; i--){
dp[j] = min(dp[j], dp[i] + rounds + cost - refundcost[i]);
curcost = min(curcost, mincost[i]);
cost += curcost;
}
}
// T = time delay
cout << dp[refundcost.size()-1] + totalrefundcost << '\n';
}
Compilation message
coach.cpp: In function 'int main()':
coach.cpp:47:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < times.size(); i++){
~~^~~~~~~~~~~~~~
coach.cpp:59:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(LL r = 1; r < stop.size(); r++){
~~^~~~~~~~~~~~~
coach.cpp:61:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < t.size(); i++){
~~^~~~~~~~~~
coach.cpp:68:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 1; j < refundcost.size(); j++){
~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
3 ms |
480 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
560 KB |
Output is correct |
7 |
Correct |
2 ms |
564 KB |
Output is correct |
8 |
Correct |
3 ms |
572 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
732 KB |
Output is correct |
18 |
Correct |
2 ms |
732 KB |
Output is correct |
19 |
Correct |
2 ms |
732 KB |
Output is correct |
20 |
Correct |
2 ms |
740 KB |
Output is correct |
21 |
Correct |
2 ms |
740 KB |
Output is correct |
22 |
Correct |
2 ms |
740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
3 ms |
480 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
560 KB |
Output is correct |
7 |
Correct |
2 ms |
564 KB |
Output is correct |
8 |
Correct |
3 ms |
572 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
732 KB |
Output is correct |
18 |
Correct |
2 ms |
732 KB |
Output is correct |
19 |
Correct |
2 ms |
732 KB |
Output is correct |
20 |
Correct |
2 ms |
740 KB |
Output is correct |
21 |
Correct |
2 ms |
740 KB |
Output is correct |
22 |
Correct |
2 ms |
740 KB |
Output is correct |
23 |
Correct |
2 ms |
740 KB |
Output is correct |
24 |
Correct |
2 ms |
740 KB |
Output is correct |
25 |
Correct |
2 ms |
740 KB |
Output is correct |
26 |
Correct |
2 ms |
740 KB |
Output is correct |
27 |
Correct |
2 ms |
740 KB |
Output is correct |
28 |
Correct |
2 ms |
740 KB |
Output is correct |
29 |
Correct |
2 ms |
740 KB |
Output is correct |
30 |
Correct |
2 ms |
740 KB |
Output is correct |
31 |
Correct |
3 ms |
740 KB |
Output is correct |
32 |
Correct |
2 ms |
740 KB |
Output is correct |
33 |
Correct |
2 ms |
740 KB |
Output is correct |
34 |
Correct |
2 ms |
740 KB |
Output is correct |
35 |
Correct |
2 ms |
740 KB |
Output is correct |
36 |
Correct |
2 ms |
740 KB |
Output is correct |
37 |
Correct |
3 ms |
740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
3 ms |
480 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
560 KB |
Output is correct |
7 |
Correct |
2 ms |
564 KB |
Output is correct |
8 |
Correct |
3 ms |
572 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
732 KB |
Output is correct |
18 |
Correct |
2 ms |
732 KB |
Output is correct |
19 |
Correct |
2 ms |
732 KB |
Output is correct |
20 |
Correct |
2 ms |
740 KB |
Output is correct |
21 |
Correct |
2 ms |
740 KB |
Output is correct |
22 |
Correct |
2 ms |
740 KB |
Output is correct |
23 |
Correct |
2 ms |
740 KB |
Output is correct |
24 |
Correct |
2 ms |
740 KB |
Output is correct |
25 |
Correct |
2 ms |
740 KB |
Output is correct |
26 |
Correct |
2 ms |
740 KB |
Output is correct |
27 |
Correct |
2 ms |
740 KB |
Output is correct |
28 |
Correct |
2 ms |
740 KB |
Output is correct |
29 |
Correct |
2 ms |
740 KB |
Output is correct |
30 |
Correct |
2 ms |
740 KB |
Output is correct |
31 |
Correct |
3 ms |
740 KB |
Output is correct |
32 |
Correct |
2 ms |
740 KB |
Output is correct |
33 |
Correct |
2 ms |
740 KB |
Output is correct |
34 |
Correct |
2 ms |
740 KB |
Output is correct |
35 |
Correct |
2 ms |
740 KB |
Output is correct |
36 |
Correct |
2 ms |
740 KB |
Output is correct |
37 |
Correct |
3 ms |
740 KB |
Output is correct |
38 |
Correct |
11 ms |
764 KB |
Output is correct |
39 |
Correct |
9 ms |
764 KB |
Output is correct |
40 |
Correct |
10 ms |
764 KB |
Output is correct |
41 |
Correct |
15 ms |
892 KB |
Output is correct |
42 |
Correct |
12 ms |
892 KB |
Output is correct |
43 |
Correct |
10 ms |
892 KB |
Output is correct |
44 |
Correct |
10 ms |
892 KB |
Output is correct |
45 |
Correct |
11 ms |
892 KB |
Output is correct |
46 |
Correct |
12 ms |
896 KB |
Output is correct |
47 |
Correct |
10 ms |
896 KB |
Output is correct |
48 |
Correct |
11 ms |
896 KB |
Output is correct |
49 |
Correct |
11 ms |
896 KB |
Output is correct |
50 |
Correct |
9 ms |
896 KB |
Output is correct |
51 |
Correct |
11 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
3 ms |
480 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
560 KB |
Output is correct |
7 |
Correct |
2 ms |
564 KB |
Output is correct |
8 |
Correct |
3 ms |
572 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
732 KB |
Output is correct |
18 |
Correct |
2 ms |
732 KB |
Output is correct |
19 |
Correct |
2 ms |
732 KB |
Output is correct |
20 |
Correct |
2 ms |
740 KB |
Output is correct |
21 |
Correct |
2 ms |
740 KB |
Output is correct |
22 |
Correct |
2 ms |
740 KB |
Output is correct |
23 |
Correct |
2 ms |
740 KB |
Output is correct |
24 |
Correct |
2 ms |
740 KB |
Output is correct |
25 |
Correct |
2 ms |
740 KB |
Output is correct |
26 |
Correct |
2 ms |
740 KB |
Output is correct |
27 |
Correct |
2 ms |
740 KB |
Output is correct |
28 |
Correct |
2 ms |
740 KB |
Output is correct |
29 |
Correct |
2 ms |
740 KB |
Output is correct |
30 |
Correct |
2 ms |
740 KB |
Output is correct |
31 |
Correct |
3 ms |
740 KB |
Output is correct |
32 |
Correct |
2 ms |
740 KB |
Output is correct |
33 |
Correct |
2 ms |
740 KB |
Output is correct |
34 |
Correct |
2 ms |
740 KB |
Output is correct |
35 |
Correct |
2 ms |
740 KB |
Output is correct |
36 |
Correct |
2 ms |
740 KB |
Output is correct |
37 |
Correct |
3 ms |
740 KB |
Output is correct |
38 |
Correct |
11 ms |
764 KB |
Output is correct |
39 |
Correct |
9 ms |
764 KB |
Output is correct |
40 |
Correct |
10 ms |
764 KB |
Output is correct |
41 |
Correct |
15 ms |
892 KB |
Output is correct |
42 |
Correct |
12 ms |
892 KB |
Output is correct |
43 |
Correct |
10 ms |
892 KB |
Output is correct |
44 |
Correct |
10 ms |
892 KB |
Output is correct |
45 |
Correct |
11 ms |
892 KB |
Output is correct |
46 |
Correct |
12 ms |
896 KB |
Output is correct |
47 |
Correct |
10 ms |
896 KB |
Output is correct |
48 |
Correct |
11 ms |
896 KB |
Output is correct |
49 |
Correct |
11 ms |
896 KB |
Output is correct |
50 |
Correct |
9 ms |
896 KB |
Output is correct |
51 |
Correct |
11 ms |
896 KB |
Output is correct |
52 |
Execution timed out |
2052 ms |
14264 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |