The Great Trunk Migration

Company: GoCommotion_26thjuly

Difficulty: medium

Problem Statement

The Bijli Circus is packing up after its final show of the season, and now comes the hardest part: getting all n elephants across the old wooden bridge to the other side of the river, where the trucks are waiting. The bridge is ancient, creaky, and has a strict weight limit of x — if the elephants currently on the bridge together weigh more than x , the whole thing collapses (and nobody wants that, especially not the elephants). Each elephant has its own individual weight, and thankfully every single elephant, on its own, weighs no more than x , so every elephant can cross alone if it has to. The ringmaster, being the impatient sort, wants to get every elephant across using as few trips over the bridge as possible . On each trip you choose any group of elephants that have not crossed yet, send them across together, and they are done — as long as their combined weight does not exceed x . You can group elephants however you like on each trip; the only rule is the weight limit per trip, a