#P11791. Maximizing Reachable Stations
Maximizing Reachable Stations
Maximizing Reachable Stations
JOI Railway Company is the only railway company in JOI country. Along a certain railway line, there are n stations numbered from 1 to n. Currently, there are two types of trains in service: a normal train and a high‐speed train.
The normal train stops at every station. It takes A minutes to travel from station i to station i+1 for each i (1 ≤ i < n).
The high–speed train stops only at stations S1, S2, …, SM (with S1 = 1 and SM = n). It takes B minutes to travel from station i to station i+1 for every segment, but you can only board or alight at the high–speed stops.
Now, JOI Railway Company plans to introduce a third type of service: the quasi–high–speed train. For each i (1 ≤ i < n), when the train is running (between two stations where it stops) it takes C minutes to traverse from station i to station i+1. The stopping stations for the quasi–high–speed train have not yet been decided, but they must satisfy the following requirements:
- All stations where the high–speed train stops must also be stops for the quasi–high–speed train.
- The quasi–high–speed train must stop at exactly K stations.
JOI Railway Company wishes to maximize the number of stations (other than station 1) that can be reached from station 1 within T minutes. In this calculation, waiting and transfer times are ignored. You may take any combination of the three services. Note that if you wish to ride either the high–speed train or the quasi–high–speed train, you can only board or alight at a station where that train stops.
For a given arrangement of the quasi–high–speed stops (which must include all high–speed stops and have exactly K stops), the time required to travel from station 1 to station i can be computed as the minimum of the following:
- The normal train: time = A × (i − 1).
- If station i is a high–speed stop: high–speed time = B × (i − 1).
- The quasi–high–speed option: you may ride the quasi–high–speed train to some station p (which must be one of its stops and is optimally chosen) and then continue by normal train from station p to station i. With an optimal choice of stops, this travel time can be computed as follows:
If i ≤ K, we can include all stations 1 through i as stops, and the quasi–high–speed time is (i − 1) × C.
Otherwise, if i > K, the best you can do is to have stops at stations 1, 2, …, K (optimally chosen) and then transfer to the normal train. In that case the time is (K − 1) × C + (i − K) × A.
Your task is to compute the maximum number of stations (excluding station 1) for which the minimum travel time is at most T minutes, assuming an optimal choice of the quasi–high–speed train stops subject to the described constraints.
Input Format: The input is given in two lines. The first line contains seven integers n, A, B, C, K, T, and M, where M is the number of high–speed stops. The second line contains M distinct integers in increasing order: S1, S2, …, SM (with S1 = 1 and SM = n).
Output Format: Output a single integer: the maximum number of stations (excluding station 1) that can be reached from station 1 within T minutes.
inputFormat
The first line contains seven space‐separated integers: n (n ≥ 2), A, B, C, K (K ≥ number of high–speed stops), T, and M (the number of high–speed stops).
The second line contains M space–separated integers: S1, S2, …, SM in increasing order, where S1 = 1 and SM = n.
outputFormat
Output a single integer representing the maximum number of stations (other than station 1) that can be reached within T minutes.
sample
10 5 3 2 4 20 3
1 5 10
5