#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
LL cnt(LL m, LL a, LL b, LL T){
a -= m;
b -= m;
if(b < 0) return 0;
a = max(a, 0LL);
b = max(b, 0LL);
LL f = (a+T-1)/T;
LL g = (b)/T;
return max(g-f+1, 0LL);
}
int main(){
cin.sync_with_stdio(0); cin.tie(0);
LL X, N, M, W, T;
cin >> X >> N >> M >> W >> T;
// 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;
stop.push_back(s);
}
stop.push_back(X);
sort(stop.begin(), stop.end());
// W = cost
vector<pair<LL,LL> > times;
LL totalrefundcost = 0;
for(LL i = 0; i < M; i++){
LL d, c;
cin >> d >> c;
times.push_back({d,c});
totalrefundcost += c;
}
sort(times.begin(), times.end());
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 < M; 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;
for(int j = 1; j < refundcost.size(); j++){
for(int i = 0; i < j; i++){
LL cost = dp[i];
for(int k = i+1; k < j; k++){
cost += refundcost[k];
}
cost += W * cnt(t[i], 0, X, T);
// keep i, j for sure
// can only throw people off at stations % T in (t[i], t[j])
int next = i+1;
for(int r = 0; r < stop.size() - 1; r++){
LL R = stop[r+1];
if(t[i] < (R % T) && (R % T) < t[j]){
while(t[next] < (R%T)){
// can kick off
cost += W * (cnt(t[next], 0, R, T) - 1);
next++;
}
}
}
while(next < j){
cost += W * cnt(t[next], 0, X, T);
next++;
}
dp[j] = min(dp[j], cost);
}
}
// T = time delay
cout << dp[refundcost.size()-1] << '\n';
}
Compilation message
coach.cpp: In function 'int main()':
coach.cpp:57:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 1; j < refundcost.size(); j++){
~~^~~~~~~~~~~~~~~~~~~
coach.cpp:67:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int r = 0; r < stop.size() - 1; r++){
~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
492 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
3 ms |
612 KB |
Output is correct |
6 |
Correct |
2 ms |
792 KB |
Output is correct |
7 |
Correct |
2 ms |
792 KB |
Output is correct |
8 |
Correct |
2 ms |
792 KB |
Output is correct |
9 |
Correct |
2 ms |
888 KB |
Output is correct |
10 |
Correct |
3 ms |
888 KB |
Output is correct |
11 |
Correct |
2 ms |
888 KB |
Output is correct |
12 |
Correct |
2 ms |
888 KB |
Output is correct |
13 |
Correct |
2 ms |
888 KB |
Output is correct |
14 |
Correct |
2 ms |
888 KB |
Output is correct |
15 |
Correct |
3 ms |
888 KB |
Output is correct |
16 |
Correct |
2 ms |
888 KB |
Output is correct |
17 |
Correct |
2 ms |
888 KB |
Output is correct |
18 |
Correct |
4 ms |
888 KB |
Output is correct |
19 |
Correct |
2 ms |
888 KB |
Output is correct |
20 |
Correct |
3 ms |
888 KB |
Output is correct |
21 |
Correct |
2 ms |
888 KB |
Output is correct |
22 |
Correct |
2 ms |
888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
492 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
3 ms |
612 KB |
Output is correct |
6 |
Correct |
2 ms |
792 KB |
Output is correct |
7 |
Correct |
2 ms |
792 KB |
Output is correct |
8 |
Correct |
2 ms |
792 KB |
Output is correct |
9 |
Correct |
2 ms |
888 KB |
Output is correct |
10 |
Correct |
3 ms |
888 KB |
Output is correct |
11 |
Correct |
2 ms |
888 KB |
Output is correct |
12 |
Correct |
2 ms |
888 KB |
Output is correct |
13 |
Correct |
2 ms |
888 KB |
Output is correct |
14 |
Correct |
2 ms |
888 KB |
Output is correct |
15 |
Correct |
3 ms |
888 KB |
Output is correct |
16 |
Correct |
2 ms |
888 KB |
Output is correct |
17 |
Correct |
2 ms |
888 KB |
Output is correct |
18 |
Correct |
4 ms |
888 KB |
Output is correct |
19 |
Correct |
2 ms |
888 KB |
Output is correct |
20 |
Correct |
3 ms |
888 KB |
Output is correct |
21 |
Correct |
2 ms |
888 KB |
Output is correct |
22 |
Correct |
2 ms |
888 KB |
Output is correct |
23 |
Correct |
15 ms |
888 KB |
Output is correct |
24 |
Correct |
15 ms |
888 KB |
Output is correct |
25 |
Correct |
17 ms |
936 KB |
Output is correct |
26 |
Correct |
17 ms |
940 KB |
Output is correct |
27 |
Correct |
14 ms |
948 KB |
Output is correct |
28 |
Correct |
17 ms |
948 KB |
Output is correct |
29 |
Correct |
14 ms |
948 KB |
Output is correct |
30 |
Correct |
15 ms |
948 KB |
Output is correct |
31 |
Correct |
18 ms |
948 KB |
Output is correct |
32 |
Correct |
15 ms |
964 KB |
Output is correct |
33 |
Correct |
19 ms |
964 KB |
Output is correct |
34 |
Correct |
15 ms |
964 KB |
Output is correct |
35 |
Correct |
14 ms |
992 KB |
Output is correct |
36 |
Correct |
14 ms |
992 KB |
Output is correct |
37 |
Correct |
17 ms |
992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
492 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
3 ms |
612 KB |
Output is correct |
6 |
Correct |
2 ms |
792 KB |
Output is correct |
7 |
Correct |
2 ms |
792 KB |
Output is correct |
8 |
Correct |
2 ms |
792 KB |
Output is correct |
9 |
Correct |
2 ms |
888 KB |
Output is correct |
10 |
Correct |
3 ms |
888 KB |
Output is correct |
11 |
Correct |
2 ms |
888 KB |
Output is correct |
12 |
Correct |
2 ms |
888 KB |
Output is correct |
13 |
Correct |
2 ms |
888 KB |
Output is correct |
14 |
Correct |
2 ms |
888 KB |
Output is correct |
15 |
Correct |
3 ms |
888 KB |
Output is correct |
16 |
Correct |
2 ms |
888 KB |
Output is correct |
17 |
Correct |
2 ms |
888 KB |
Output is correct |
18 |
Correct |
4 ms |
888 KB |
Output is correct |
19 |
Correct |
2 ms |
888 KB |
Output is correct |
20 |
Correct |
3 ms |
888 KB |
Output is correct |
21 |
Correct |
2 ms |
888 KB |
Output is correct |
22 |
Correct |
2 ms |
888 KB |
Output is correct |
23 |
Correct |
15 ms |
888 KB |
Output is correct |
24 |
Correct |
15 ms |
888 KB |
Output is correct |
25 |
Correct |
17 ms |
936 KB |
Output is correct |
26 |
Correct |
17 ms |
940 KB |
Output is correct |
27 |
Correct |
14 ms |
948 KB |
Output is correct |
28 |
Correct |
17 ms |
948 KB |
Output is correct |
29 |
Correct |
14 ms |
948 KB |
Output is correct |
30 |
Correct |
15 ms |
948 KB |
Output is correct |
31 |
Correct |
18 ms |
948 KB |
Output is correct |
32 |
Correct |
15 ms |
964 KB |
Output is correct |
33 |
Correct |
19 ms |
964 KB |
Output is correct |
34 |
Correct |
15 ms |
964 KB |
Output is correct |
35 |
Correct |
14 ms |
992 KB |
Output is correct |
36 |
Correct |
14 ms |
992 KB |
Output is correct |
37 |
Correct |
17 ms |
992 KB |
Output is correct |
38 |
Execution timed out |
2061 ms |
1008 KB |
Time limit exceeded |
39 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
492 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
3 ms |
612 KB |
Output is correct |
6 |
Correct |
2 ms |
792 KB |
Output is correct |
7 |
Correct |
2 ms |
792 KB |
Output is correct |
8 |
Correct |
2 ms |
792 KB |
Output is correct |
9 |
Correct |
2 ms |
888 KB |
Output is correct |
10 |
Correct |
3 ms |
888 KB |
Output is correct |
11 |
Correct |
2 ms |
888 KB |
Output is correct |
12 |
Correct |
2 ms |
888 KB |
Output is correct |
13 |
Correct |
2 ms |
888 KB |
Output is correct |
14 |
Correct |
2 ms |
888 KB |
Output is correct |
15 |
Correct |
3 ms |
888 KB |
Output is correct |
16 |
Correct |
2 ms |
888 KB |
Output is correct |
17 |
Correct |
2 ms |
888 KB |
Output is correct |
18 |
Correct |
4 ms |
888 KB |
Output is correct |
19 |
Correct |
2 ms |
888 KB |
Output is correct |
20 |
Correct |
3 ms |
888 KB |
Output is correct |
21 |
Correct |
2 ms |
888 KB |
Output is correct |
22 |
Correct |
2 ms |
888 KB |
Output is correct |
23 |
Correct |
15 ms |
888 KB |
Output is correct |
24 |
Correct |
15 ms |
888 KB |
Output is correct |
25 |
Correct |
17 ms |
936 KB |
Output is correct |
26 |
Correct |
17 ms |
940 KB |
Output is correct |
27 |
Correct |
14 ms |
948 KB |
Output is correct |
28 |
Correct |
17 ms |
948 KB |
Output is correct |
29 |
Correct |
14 ms |
948 KB |
Output is correct |
30 |
Correct |
15 ms |
948 KB |
Output is correct |
31 |
Correct |
18 ms |
948 KB |
Output is correct |
32 |
Correct |
15 ms |
964 KB |
Output is correct |
33 |
Correct |
19 ms |
964 KB |
Output is correct |
34 |
Correct |
15 ms |
964 KB |
Output is correct |
35 |
Correct |
14 ms |
992 KB |
Output is correct |
36 |
Correct |
14 ms |
992 KB |
Output is correct |
37 |
Correct |
17 ms |
992 KB |
Output is correct |
38 |
Execution timed out |
2061 ms |
1008 KB |
Time limit exceeded |
39 |
Halted |
0 ms |
0 KB |
- |