PDP-24 (2012) - Camp seniors - 1 (cutpoly)

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python

CUTPOLY

A polygonal line with N points in the plane is given. The points are sorted by x-coordinate, i.e., x_i + 1 > x_i, and also the polygonal line is strictly increasing with respect to y-coordinate, i.e., y_{i+1} > y_i.

Let y = y_1, and y = y_N be lines parallel to the x-axis. We can bring a line x = λ parallel to the y-axis, which intersects the polygonal line at a point (x_1 \le λ \le x_N). It may intersect at any of the N points given or it may intersect any of the N - 1 line segments formed. Let L(λ) be the area enclosed by the polygonal line, the line y = y_1, and the line x = λ. Let U(λ) be the area enclosed by the polygonal line, the line y = y_N, and the line x = λ.

The task is to determine the minimum value of L(λ) + U(λ).

Input

The first line of the input contains only the integer N, the number of points of the polygonal line. Each of the next N lines contains a pair of integers separated by a space, corresponding to the x and y coordinates respectively of each point of the line. The points will be given sorted by the x dimension.

Output

The output should consist of a real number, the minimum possible value of L(λ) + U(λ), with an accuracy of 6 decimal places. Attention! Be sure to print with "%0.6lf\n" or something similar.

Constraints

2 \le N \le 1.000.000.
Execution time limit: 1 sec.
Memory limit: 64 MB.

Example of Input - Output

STDIN (cutpoly.in)

4
1 1
3 2
8 5
9 7

STDOUT (cutpoly.out)

12.833333

pdp-2012-camp-s1.svg


Comments

There are no comments at the moment.