P2945 [USACO09MAR] Sand Castle S
Description
Farmer John has built a sand castle! Like all good castles, the walls have crennelations, that nifty pattern of embrasures (gaps) and merlons (filled spaces); see the diagram below. The N (1
Input Format
\* Line 1: Three space-separated integers: N, X, and Y
\* Lines 2..N+1: Line i+1 contains the two space-separated integers: M\_i and B\_i
Output Format
\* Line 1: A single integer, the minimum cost needed to rebuild the castle
Explanation/Hint
FJ's castle starts with heights of 3, 1, and 1. He would like to change them so that their heights are 1, 2, and 2, in some order. It costs 6 to add a unit of height and 5 to remove a unit of height.
FJ reduces the first merlon's height by 1, for a cost of 5 (yielding merlons of heights 2, 1, and 1). He then adds one unit of height to the second merlon for a cost of 6 (yielding merlons of heights 2, 2, and 1).