Relocation
InterviewTime limit1sMemory limit128 MB
Split up to 10 furniture items between two cars with capacity limits so that every item gets moved in the fewest number of paired trips.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Binary search, Brute force, Backtracking
- Solved
- No attempts yet
Problem
Emma and Eric are moving into the new house they bought after returning from their honeymoon. Luckily, a few friends are helping with the move. To carry the furniture they only have two small cars, which makes things a little complicated. The furniture does not fit inside the cars, so Eric wants to put it on the roofs instead. However, each car's roof can bear only a limited weight, so several trips will be needed to move everything.
The move works like this:
- At the old house, they load furniture onto the two cars.
- They drive both cars to the new house and carry the furniture upstairs.
- Everyone returns to the old house, and the process repeats until all the furniture has been moved.
The whole group always travels together so the move stays fun and nobody is left alone. Because the two houses are far apart, Eric wants to make as few trips as possible.
Given the weight of each piece of furniture and the roof capacities and of the two cars, how many trips to the new house are required to move all the furniture? A car with capacity may carry furniture whose total weight is at most on any single trip.
Input
The first line contains the number of scenarios. Each scenario is given on two lines. The first line contains three integers , , and : the number of pieces of furniture () and the roof capacities and (). The second line contains integers , the weights of the furniture (). Every piece of furniture can be carried by at least one of the two cars.
Output
For each scenario, first print a line Scenario #i:, where is the scenario number starting from 1. On the next line, print the minimum number of trips to the new house needed to move all the furniture. Separate consecutive scenarios with a blank line.