Two Stickers
InterviewTime limit2sMemory limit512 MB
Given an H by W grid and N rectangles that may rotate, place two non-overlapping rectangles inside and maximize their total area.
- Level
Medium5 of 10
- Topics
- Implementation, Brute force, Greedy, Geometry
- Solved
- No attempts yet
Problem
There is a grid paper of size H×W and N stickers. The size of the i-th sticker is Ri×Ci. The grid paper is divided into cells of size 1×1, with lines drawn at intervals of 1.
Today you want to attach two stickers to the grid paper. The sides of a sticker must align with the grid lines, and the two stickers must not overlap. However, the stickers may touch. A sticker may be rotated 90 degrees. A sticker cannot go outside the grid paper.
Find the maximum total area covered by the two attached stickers.
Input
The first line gives the size of the grid paper, H and W, and the second line gives the number of stickers, N. The following N lines give the sizes of the stickers, Ri and Ci.
Output
On the first line, print the maximum total area covered by the two attached stickers. If the two stickers cannot be attached, print 0.
Constraints
- 1 ≤ H, W, N ≤ 100
- 1 ≤ Ri, Ci ≤ 100