Task
On a field, there are two stacks of hay bales.
The first stack contains bales, where the first bale is at the bottom, and the bale is at the top. The bale has weight .
The second stack contains bales, where the first bale is at the bottom, and the bale is at the top. The bale has weight .
You want to transport the bales to the processing plant using a tractor with a total load limit . In one trip, you may load bales from both stacks, but a bale cannot be loaded before the bales on top of it have been loaded. The total weight of the bales loaded into the tractor on each trip must not exceed .
Determine the minimum number of trips required to clear the two stacks.
Input data
The first line contains three integers representing the number of bales from the first stack , the number of bales from the second stack , and the load limit of the tractor .
The second line contains integers .
The third line contains integers .
Output data
The output consists of a single integer representing the minimum number of trips needed to transport all bales.
Constraints and clarifications
# | Points | Constraints |
---|---|---|
1 | 2 | |
2 | 3 | |
3 | 7 | |
4 | 21 | |
5 | 30 | |
6 | 37 | No further constraints |
Example
stdin
4 5 10
4 3 7 5
3 4 3 6 2
stdout
4
Explanation
The minimum number of trips required to clear the two stacks is ; this can be achieved in the following way:
- On the first trip, we take the following from the two stacks: the hay bales with weights and with a total weight of ;
- On the second trip, the hay bales with weights and with a total weight of ;
- On the third trip, the hay bales with weights and with a total weight of ;
- On the fourth trip, the hay bales with weights and with a total weight of .