#K59917. Fuel-Constrained Navigation

    ID: 30971 Type: Default 1000ms 256MiB

Fuel-Constrained Navigation

Fuel-Constrained Navigation

You are given a journey problem where you must travel from position 0 to a target position. Each step in the journey consumes 1 unit of fuel. Along the way, there are fuel stations where your fuel can be replenished by a fixed amount, and obstacles that must be avoided. The movement is always in unit steps towards the target (i.e. +1 if the target is positive and -1 if negative).

The fuel consumption and refueling can be mathematically represented as follows:

[ f_{new} = f_{old} - 1 + \mathbf{1}_{{x \in S}} \times F, ]

where \(f_{old}\) is the current fuel, \(F\) is the fuel acquired at a fuel station, \(S\) is the set of fuel station positions, and \(\mathbf{1}_{\{x \in S\}}\) is an indicator function that is 1 if the current position \(x\) is a fuel station and 0 otherwise.

Your task is to determine if it is possible to reach the target position without running out of fuel or hitting any obstacles. If at any step you land exactly on an obstacle, the journey fails.

inputFormat

Input is given via standard input (stdin) in the following format:

target initial_fuel fuel_per_station
n
s1 s2 ... sn
m
o1 o2 ... om
  • target: an integer representing the destination position.
  • initial_fuel: an integer representing the fuel at the start.
  • fuel_per_station: an integer representing the amount of fuel gained upon visiting a fuel station.
  • n: the number of fuel stations.
  • s1, s2, ..., sn: the positions of the fuel stations (space separated).
  • m: the number of obstacles.
  • o1, o2, ..., om: the positions of the obstacles (space separated). If n or m is 0, the corresponding list will be empty.

outputFormat

Output a single line to standard output (stdout) containing either True or False depending on whether the target can be reached without hitting an obstacle or running out of fuel.

## sample
20 10 10
3
5 15 25
0
True