#K2646. Maximum Consecutive Landmarks Visited
Maximum Consecutive Landmarks Visited
Maximum Consecutive Landmarks Visited
Emma loves exploring new places by visiting landmarks. Starting from the first landmark, she wants to visit as many consecutive landmarks as possible. However, her vehicle has a limited amount of fuel.
You are given an integer \(n\) representing the number of landmarks and an integer \(f\) representing the initial fuel amount. Between each consecutive pair of landmarks \(i\) and \(i+1\) (for \(1 \leq i \leq n-1\)), a certain amount of fuel \(d_i\) is required.
Your task is to determine the maximum number of consecutive landmarks Emma can visit, starting from the first landmark. Note that the first landmark requires no fuel.
The condition for Emma to be able to visit \(k\) landmarks is given by:
[ f \geq \sum_{i=1}^{k-1} d_i ]
Output the maximum number of landmarks she can visit.
inputFormat
The input is given from standard input (stdin) and consists of two lines:
- The first line contains two integers (n) and (f), where (n) ((n \geq 1)) is the number of landmarks and (f) is the initial fuel amount.
- The second line contains (n-1) integers representing the fuel consumption required to travel between consecutive landmarks.
Note: When (n = 1), the second line will be absent.
outputFormat
Output a single integer to standard output (stdout), which is the maximum number of consecutive landmarks Emma can visit.## sample
5 10
4 6 3 5
3
</p>