One Clean Slice!
Time limit1sMemory limit16 MB
Split an R by C by H block with guillotine cuts into N boxes with one raisin each to maximize the smallest box volume.
- Level
Hard8 of 10
- Topics
- Backtracking, Binary search, Divide and conquer
- Solved
- No attempts yet
Problem
There is a tasty jelly. To make it easy to cut, the jelly is divided into unit cubes of volume 1: cells wide, cells deep and cells tall. The jelly holds raisins. No raisin spans more than one cell, and no cell holds two or more raisins. So the jelly can be read as a three dimensional array, and the position of a raisin is written as three integers . See the figure below.

Tokkaengi wants to divide the jelly into exactly pieces so that every piece holds exactly one raisin. A cut follows cell boundaries exactly, goes all the way through the piece being cut and leaves two rectangular boxes; a cut cannot stop halfway. Among the pieces, Tokkaengi wants the smallest volume to be as large as possible. Help Tokkaengi cut the jelly.
Input
The first line contains the jelly size , , and the number of raisins , separated by spaces. (, )
Each of the next lines contains three integers , , giving the position of one raisin, separated by spaces. (, , ) No two raisins share a position.
Output
Print the largest volume the smallest piece can have when the jelly is divided into exactly pieces with one raisin in each piece.
Hint

This is the jelly of the example input seen from above. However well it is cut, the three pieces have volumes 2, 3 and 4.