#C8081. Minimizing Conveyor Belt Reset Cost
Minimizing Conveyor Belt Reset Cost
Minimizing Conveyor Belt Reset Cost
You are given a conveyor belt system that processes a sequence of packets. Each packet has an associated weight. The belt has a weight capacity W and, in order to avoid overload, if the next packet would cause the total weight on the belt to exceed W, you must reset the belt. Resetting the belt incurs a cost of R (resetCost) and clears any accumulated weight.
Your task is to compute the total cost incurred to process all packets, following this procedure:
- Start with a current accumulated weight of 0.
- For each packet, if adding its weight to the current total exceeds W, perform a reset which adds R to the total cost and sets the accumulated weight back to 0.
- Add the packet's weight to the current weight.
Input and Output: The input is read from standard input and the output, the minimum cost, is printed to standard output.
The underlying strategy is a simple simulation of processing the packets.
Additionally, if a packet exactly fits the remaining capacity (or if no reset is needed), no reset cost is incurred.
Formula: If current_weight + weight > W then total_cost += R.
inputFormat
The first line of input contains three integers separated by spaces: n (the number of packets), W (the maximum weight capacity of the conveyor belt), and R (the reset cost).
The second line contains n integers separated by spaces representing the weights of the packets.
outputFormat
Output a single integer, the minimum total cost to process all packets.
## sample4 10 7
2 4 3 5
7