Semiexpress
Time limit1sMemory limit256 MB
Choose exactly K stops for a new train so that the number of stations reachable from station 1 within T minutes is maximized.
- Level
Hard8 of 10
- Topics
- Greedy, Binary search, Prefix sum
- Solved
- No attempts yet
Problem
JOI Railways is the only railway company in the Kingdom of JOI. There are stations along one railway line, numbered from to . Two kinds of trains currently run on the line: express trains and local trains.
A local train stops at every station. For each (), a local train takes minutes to go from station to station .
An express train stops only at stations (). For each (), an express train takes minutes to go from station to station .
JOI Railways plans to run a new kind of train called a semiexpress. For each (), a semiexpress train takes minutes to go from station to station . The stops of the semiexpress train are not decided yet, but they must satisfy these conditions:
- The semiexpress train stops at every station where the express train stops.
- The semiexpress train stops at exactly stations.
JOI Railways wants to choose the semiexpress stops so that the number of stations (not counting station ) that can be reached from station within minutes is as large as possible. The time a train spends standing at a station is not counted.
When traveling from station to another station, you may only ride trains in the direction of increasing station numbers. If several kinds of trains stop at station (), you can transfer between any of the trains that stop there.
Write a program that computes the maximum number of stations (not counting station ) reachable from station within minutes when the semiexpress stops are chosen optimally.
Input
Read the following data from standard input.
- The first line contains three space-separated integers : there are stations, the express train stops at stations, and the semiexpress train stops at stations.
- The second line contains three space-separated integers : a local, express, and semiexpress train takes , , and minutes respectively to go from one station to the next.
- The third line contains an integer : the goal is to maximize the number of stations (not counting station ) reachable from station within minutes.
- The -th of the next lines () contains an integer : the express train stops at station .
Output
Print one line to standard output containing the maximum number of stations that satisfy the travel time condition.
Constraints
All input data satisfy the following conditions.