#K68812. Maximizing Cities Visited

    ID: 32948 Type: Default 1000ms 256MiB

Maximizing Cities Visited

Maximizing Cities Visited

Emily wants to visit as many cities as possible, but she has a limit on the total travel time. Given the total number of cities \(N\), the travel times between consecutive cities, and the maximum allowed travel time \(T\), determine the maximum number of cities she can visit without exceeding \(T\).

Formally, let the travel times be \(t_1, t_2, \ldots, t_{N-1}\). Find the maximum integer \(k\) (where \(1 \leq k \leq N\)) such that \[ \sum_{i=1}^{k-1} t_i \leq T \] If no travel is possible without exceeding the limit, Emily remains in the starting city.

inputFormat

The input is read from stdin and consists of three lines:

  1. The first line contains an integer (N) denoting the total number of cities.
  2. The second line contains (N-1) space‐separated integers representing the travel times between consecutive cities.
  3. The third line contains an integer (T) representing the maximum allowed travel time.

outputFormat

Output a single integer on stdout that represents the maximum number of cities Emily can visit without exceeding the travel time limit (T).## sample

5
3 5 2 8
10
4

</p>