Carrying the Bags
InterviewTime limit1sMemory limit1024 MB
Given K bags, a walking time X, and a per-bag delay Y, find the trip plan that moves all bags to the award table in the least total time.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Math
- Solved
- No attempts yet
Problem
The olympiad jury asked Kevin to help move packed prizes from the jury work room to the award table. Kevin is strong enough to carry any number of bags at once. However, each additional bag takes twice as long to hook onto his arm as the one before it. The first bag takes 1 second, the second takes 2 seconds, the third takes 4 seconds, the fourth takes 8 seconds, and so on.
The bags also slow him down. Without any bags, Kevin needs seconds to walk from the jury work room to the award table (or back). Each bag he carries adds seconds to that walking time.
Write a program that finds the fastest plan for moving all the bags to the award table. Kevin starts in the jury work room, takes some number of bags, and carries them to the award table. If bags remain, he goes back to the work room for the next load. Once all bags are on the award table, Kevin waits there for the contest to end.
Input
A single line contains the space-separated integers , , and , where () is the number of prizes in bags, () is the time in seconds to walk between the jury work room and the award table without bags, and () is the number of extra seconds each bag adds to the walking time.
Output
Print the minimum total time in seconds for moving all the bags to the award table on the first line.
Print the number of trips from the jury work room to the award table on the second line.
Print space-separated integers on the third line, giving the number of bags carried on each trip. If several plans reach the minimum time, print any of them.