Hill

면접 대비

시간 제한1초메모리 제한512 MB

요약
시작점과 끝점, n개 선분의 길이가 주어질 때 다각형 사슬의 최대 y좌표를 구하고, 불가능하면 IMPOSSIBLE을 출력한다.
난이도

보통10점 중 6점

유형
기하, 그리디, 수학, 이분 탐색
정답자
아직 제출이 없습니다

문제

Having stocked up with snowballs, Zenyk and Marichka already wanted to start a game.

But suddenly, Zenyk thought that throwing snowballs on a flat surface is boring. He wanted to build as high as possible hill for himself to climb at it and throw snowballs at Marichka.

Building of a hill isn’t easy. Zenyk treated it seriously, took a sheet of paper with coordinate axes, where y-axis is directed upwards, and began to draw the cross section of a hill (a front view).

Marichka doesn’t want the hill to be too high, so she imposed some constraints at its section.

  1. Section must be a polygonal chain.
  2. The chain must start at point (x0, y0) and end at point (xn, yn).
  3. The chain must contain n segments.
  4. The length of the i-th segment should be li.

Zenyk wants to know the maximum height he of a hill he can make under these constraints, and asks you the maximal y-coordinate of the hill’s section. Help him find it.

입력

The first line contains four integers x0, y0, xn, yn (|x0|, |y0|, |xn|, |yn| ≤ 106) – coordinates of start and end of the chain.

The second line contains an integer n (1 ≤ n ≤ 105) — number of segments in the chain.

The third line contains n integers l1, . . . , ln (1 ≤ li ≤ 106) — lengths of the segments.

출력

If there is no hill that satisfies these constraints, output “IMPOSSIBLE”.

Otherwise, output one real number — the maximum y-coordinate of the highest point. The answer will be considered correct if its absolute or relative error doesn’t exceed 10−7.

예제2

  1. 예제 1

    입력
    2 3 8 3
    2
    5 5
    
    예상 출력
    7.0000000000
    
  2. 예제 2

    입력
    4 7 44 77
    4
    4 7 7 4
    
    예상 출력
    IMPOSSIBLE