#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (3005)
ll N, A; //normal train has N stations (at pos 1 to N), takes A minutes to move from i to i+1
ll M, B; //express train has M stations (at all positions in express[M]), takes B minutes to move from i to i+1
ll K, C; //semi-express train has K stations, takes C minutes to move from i to i+1
ll T;
ll express[MAXN];
priority_queue<pair<ll,ll> > pq;
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
cin>>N>>M>>K>>A>>B>>C>>T;
for(ll i = 0;i < M;i++){
cin>>express[i];
}
ll sum = 0;
if(B * (N - 1) <= T) sum = 0;
else sum = -1;
ll P[M - 1];
for(ll i = 0;i < M - 1;i++){
if(B * (express[i]-1) > T){
continue;
}
ll u = min(express[i + 1] - 1,express[i] + (T - B * (express[i]-1)) / A);
sum += (u - express[i] + 1);
P[i] = u + 1;
if(P[i] < express[i + 1] && B * (express[i] - 1) + C * (P[i]-express[i]) <= T){
pq.push({min(express[i + 1] - 1, P[i] + (T - B * (express[i]-1) - C * (P[i]-express[i])) / A) - P[i] + 1, i});
}
}
for(ll i = 0;i < K - M;i++){
if(pq.empty()){
break;
}
ll v = pq.top().first;
ll ind = pq.top().second;
pq.pop();
sum += v;
P[ind] += v;
if(P[ind] < express[ind + 1] && B * (express[ind]-1) + C * (P[ind]-express[ind]) <= T){
pq.push({min(express[ind + 1] - 1, P[ind] + (T - B * (express[ind] - 1) - C * (P[ind]-express[ind])) / A) - P[ind] + 1, ind});
}
}
cout<<sum<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
352 KB |
Output is correct |
22 |
Correct |
1 ms |
440 KB |
Output is correct |
23 |
Correct |
1 ms |
352 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |