Postering
Time limit1sMemory limit128 MB
Given adjacent buildings with widths and heights, find the minimum number of non-overlapping rectangles needed to cover the whole skyline shape.
Problem
All the buildings in the eastern district of Byteburg were built in the old style: they stand right next to one another with no gaps in between. Together they form a very long chain of buildings of varying heights, stretching from east to west.
The mayor of Byteburg, Byteasar, has decided to cover the northern face of the chain with posters. He wonders about the smallest number of posters that suffices to cover the whole northern face. Each poster is a rectangle with vertical and horizontal sides. Posters may not overlap, but they may touch, that is, share points along their edges. Every poster must lie flush against the walls of some buildings, and the entire surface of the northern face must be covered.
Write a program that:
- reads the description of the buildings from standard input,
- determines the minimum number of posters needed to cover their northern faces completely,
- writes the result to standard output.
Input
The first line contains one integer (), the number of buildings in the chain. Each of the next lines contains two integers and (), separated by a single space, giving respectively the width and the height of the -th building in the row.
Output
Output a single integer: the minimum number of rectangular posters that suffice to cover the northern faces of the buildings.
Hint
The figures below illustrate an example. The first shows the northern face of a chain of buildings, and the second shows one way to cover that face with four posters.

