#K1556. Packages Delivery Optimization

    ID: 24383 Type: Default 1000ms 256MiB

Packages Delivery Optimization

Packages Delivery Optimization

You are given the number of packages n, a maximum travel distance D, and a list of distances representing each package's required delivery distance. The packages must be delivered in order; once the cumulative sum of the delivered distances would exceed D, the delivery stops. Your task is to determine the maximum number of packages that can be delivered without exceeding the distance D.

Note: The cumulative sum must never exceed \(D\). For example, if the package distances are \(d_1, d_2, \dots, d_n\), you need to find the largest \(k\) such that \(\sum_{i=1}^{k} d_i \le D\).

inputFormat

The input is given via standard input (stdin) and consists of two lines:

  • The first line contains two integers separated by space: \(n\) (the number of packages) and \(D\) (the maximum distance the vehicle can travel).
  • The second line contains \(n\) space-separated integers representing the distances for each package in order.

outputFormat

The output should be printed to standard output (stdout) and is a single integer: the maximum number of packages that can be delivered without exceeding the distance \(D\).

## sample
6 100
30 20 50 10 40 50
3

</p>