Balloon Party
InterviewTime limit1sMemory limit2048 MB
Given a grid of ceiling heights, find the maximum volume of helium the tent can hold without any of it spilling over the lowest edge.
Problem
The Floating Poodle Company (FPC) plans to sell balloon animals at festivals. To make the animals float, they will fill them with helium. They have run out of helium canisters, so they will store their helium below the ceilings of the party tents where they sell the balloons.
Because of environmental laws, they may not spill any helium. They must not put too much helium into any tent. If the helium level drops below any part of the edges of the ceiling, the surplus helium will blow away and contaminate the atmosphere. They ask you to calculate the maximum amount of helium they can fit inside one of the tents.
Input
One line with two integers and (, ): the width and length of the tent.
Then lines follow, each with integers in the range . Each integer is the height above the ground of a section of the tent ceiling. Assume that every section is completely horizontal.
Output
The maximum amount of helium that the company can fit below the ceiling of the tent.