#C5076. Closest Checkpoint Within Fuel Capacity
Closest Checkpoint Within Fuel Capacity
Closest Checkpoint Within Fuel Capacity
You are given n checkpoints with their distances from Earth and a fuel capacity f. Your task is to determine the closest checkpoint that can be reached within the available fuel. In other words, given a list of distances \(d_1, d_2, \ldots, d_n\), find the smallest distance \(d_i\) such that \(d_i \leq f\). If no checkpoint satisfies this condition, output -1.
Input Constraints:
- The first line contains two integers, n (number of checkpoints) and f (fuel capacity).
- The second line contains n space-separated integers representing the distances.
Output: Print a single integer which is the distance of the closest reachable checkpoint. If there is no reachable checkpoint, print -1.
inputFormat
The first line contains two integers: n
and f
.
The second line contains n
space-separated integers representing the distances of the checkpoints from Earth.
outputFormat
Output a single integer: the distance of the closest checkpoint that is \(\leq f\). If no checkpoint can be reached, output -1.
## sample5 100
150 300 500 650 700
-1
</p>