#C8511. Calculate Successful Trips
Calculate Successful Trips
Calculate Successful Trips
You are given several datasets. In each dataset, a delivery robot is tasked with transporting a series of items. Each dataset is described by three parameters:
- n: the total number of items.
- m: the weight capacity of the robot per trip.
- k: the maximum number of trips the robot can make.
Following these parameters is a list of n integers representing the weights of the items. The robot will attempt to transport items in the given order. For each item, if the current item has a weight \(w\) that does not exceed the robot's capacity \(m\) and the robot has not yet reached its maximum number of trips (i.e. the number of successful trips so far is less than \(k\)), then the robot will perform one trip to carry that item. If an item weighs more than \(m\), the robot will skip that item without consuming a trip.
Your task is to compute the total number of successful trips for each dataset.
Note: The robot processes the items in order and does not attempt to rearrange them.
inputFormat
The input is given via stdin and consists of several datasets. Each dataset is described by two lines:
- The first line contains three integers: n, m, and k, separated by spaces.
- The second line contains n integers, which represent the weights of the items separated by spaces. (If n is zero, this line will be empty.)
The end of input is indicated by a line containing a single zero (0
).
outputFormat
For each dataset, print the total number of successful trips on a separate line via stdout.
## sample4 50 3
15 25 35 45
3 70 2
50 20 90
0
3
2
</p>