아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Goofy Golf

면접 대비

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

요약
나무나 기둥을 넘지 않으면서 반원 궤적으로 골프공을 s에서 t까지 옮기는 최소 타수를 구한다.
난이도

보통10점 중 7점

유형
그래프, BFS, 기하, 그리디
정답자
아직 제출이 없습니다

문제

Goofy is a professional golf player. Today he is playing golf in a 2D cartesian plane, where y = 0 is the ground. The golf field spans from x = a to x = b and you can assume that there are infinitely tall posts on x = a and x = b.

The ball is currently located on x = s (i.e. coordinate (s, 0)) and the hole is located on x = t (i.e. coordinate (t, 0)). There are also N trees on the golf field. The ith tree is located on x = Pi and is Hi units tall. In other words, the ith tree can be represented as a line segment from (Pi, 0) to (Pi, Hi).

In a single golf strike, Goofy can hit the golf ball and it will move from (x, 0) to (x + 2r, 0) for any real number (not necessarily integer) r, and the trajectory of the golf ball is a semi-circle centered at (x + r, 0) and radius |r|. The golf ball must not hit any part of a tree except on its top endpoint. The golf ball must also not hit any part of a post. In other words, the golf ball’s trajectory must not pass through:

  • Any point (Pi, y) for all 0 ≤ y < Hi; 1 ≤ i ≤ N
  • Any point (a, y) and any point (b, y) for all 0 ≤ y.

As standard golf rules, Goofy wants to minimize the number of strikes to move the ball to the hole, i.e. coordinate (t, 0). Help Goofy to count the minimum number of strikes required to move the ball from (s, 0) to (t, 0), or indicate if it is impossible to do so.

입력

Input begins with a line containing five integers: N a b s t (1 ≤ N ≤ 2000; 0 ≤ a < s < t < b ≤ 109) representing the number of trees, the location of the posts, the initial location of the ball, and the location of the hole, respectively. The next line contains N integers: Pi (a < P1 < P2 < · · · < PN < b; Pi ≠ s; Pi ≠ t) representing the location of the trees. The next line contains N integers: Hi (0 < Hi ≤ 109) representing the height of the trees.

출력

Output in a line an integer representing the minimum number of strikes required to move the ball from (s, 0) to (t, 0), or -1 if it is impossible to do so.

예제3

  1. 예제 1

    입력
    2 1 9 2 8
    4 5
    1 3
    
    예상 출력
    1
    
  2. 예제 2

    입력
    2 1 9 2 6
    4 5
    1 3
    
    예상 출력
    2
    
  3. 예제 3

    입력
    3 1 9 2 8
    4 5 6
    1 3 4
    
    예상 출력
    -1