#P12504. 「CEOI2025」割草机
「CEOI2025」割草机
Description
After his adventures in Poenari Fortress, Vlad returns home and, as a true Romanian, his first thought is that he should feed his horse. The horse is not very picky when it comes to food, so Vlad uses his lawn as a primary source of food for it.
For this task, Vlad has a lawn mower of capacity . He decided to split his lawn into lanes, numbered from to , which he has to mow in this order. Each lane contains a quantity of uncut grass and, due to some unknown reasons, it takes seconds for Vlad to push the mower over that lane.
After going over a few lanes, the mower may reach full capacity, in which case it stops cutting grass, leaving some on that lane. Every time that happens, its collector tank needs to be emptied, which takes seconds and can be done only at the end of a lane. If the collector tank fills up while Vlad is going over lane , he needs to keep pushing the mower until the end of the lane, empty the tank and then go over the lane one more time (or as many times as needed) in order to cut the left-over grass. For example if for a lane we have to pass through it times to get rid of all the grass, that will take seconds. After mowing the entire lawn, the mower must be emptied.
After a lot of thinking and complaining that it will take him way too much to finish mowing, Vlad arrived at the conclusion that sometimes it might be more time-efficient to empty the collector tank even before it reaches full capacity, but he is not sure what is the best strategy he can use. Therefore, he asks for your help.
Given the quantity of grass on each lane and the number of seconds it takes to push the mower over each lane, the capacity of the tank and the time it takes to empty it, find the best way for Vlad to finish mowing his lawn in minimum time.
Implementation Details
You should implement the following procedure.
long long mow(int n, int c, int b, std::vector<int> &a, std::vector<int> &v);
- : the number of lanes of the lawn
- : the total capacity of the collector tank
- : the number of seconds to empty the tank
- : vector of length describing the time it takes to go over each lane
- : vector of length giving the quantity of grass on each lane
- This procedure should return a single integer, the minimum time to mow the lawn.
- This procedure is called exactly once for each test case.
Constraints
- (for each such that )
- (for each such that )
- It is guaranteed that the correct result will be at most
Subtasks
- (9 points) All the given values (, , , and ) will be at most
- (16 points) and for all
- (36 points)
- (17 points)
- (22 points) No additional constraints
Example 1
Consider the following call:
mow(3, 5, 2, {2, 10, 3}, {2, 4, 6})
In this sample, there are lanes, the collector tank has a capacity of and it takes seconds to empty it.
For this sample, Vlad will mow the first lane in seconds. The amount of grass in the mower will be . Then he will empty the mower in seconds. On the first strip, he spends seconds.
He will then pass through the second lane. He will mow units of grass. He will choose not to empty the tank after finishing the second strip. The time spent on the second strip is seconds.
For the third strip, he starts mowing. After one unit of grass, his mower fills up, thus he has to go until the end of the strip, empty the mower, then start mowing through third strip again. Keep in mind that after the entire yard is mowed, the mower has to be emptied. The time spent on the third strip is seconds.
In total, he spends seconds. It can be proven that this is the optimal strategy that Vlad uses to mow the lawn.
Example 2
Consider the following call:
mow(4, 10, 4, {1, 2, 1, 4}, {3, 2, 6, 7})
In this sample, there are lanes, the collector tank has a capacity of and it takes seconds to empty it.
The optimal strategy is just to go over the first lanes and afterwards the tank will be filled and the vector of grass quantities will be [0, 0, 1, 7]
. After that, the tank should be emptied and the last lanes will be mowed and the tank will be emptied again at the end.
The total number of seconds will be .
Sample grader
The sample grader reads the input in the following format:
- line :
- line :
- line :
and outputs the result of the call to mow
with the corresponding parameters.