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

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

Jumping Jack

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

요약
정렬된 체크포인트 위치가 주어질 때, 잭이 정확히 k번 점프해 처음에서 마지막 체크포인트까지 도달하는 최대 점프 레벨을 구하고, 불가능하면 -1을 출력한다.
난이도

보통10점 중 7점

유형
이분 탐색, 그리디, 투 포인터, 배열
정답자
아직 제출이 없습니다

문제

For as long as he could remember, Jack has loved to jump. His goal is to become an Olympic athlete someday, so he spends lots of time practicing his jumping skills. Jack has set up a course of checkpoints along a straight line from his starting point. To go through this course, Jack picks a jumping level, which defines how far he can travel along these checkpoints. Specifically, if Jack is at a checkpoint located at position ii and has picked jumping level jj, he will jump to the furthest checkpoint that is at or before position i+ji + j. If there is no checkpoint in the range \[i+1,i+j]\[i + 1, i + j], then Jack will fail to finish the course because he cannot make a jump.

Jack wants to know how he should pick his jumping level so that he can make it through the course. Additionally, in order to get in enough practice without overexercising, Jack wants to finish the course in exactly kk jumps. Given the positions of all the checkpoints, find the maximum jump level that Jack should pick to make it through the course with exactly kk jumps or determine if it is impossible to do so.

입력

The first line of input is 22 integers separated by spaces nn and kk such that 3≤n≤1063 \leq n \leq 10^6 and 2≤k<n2 \leq k < n. The next line is nn distinct integers in sorted order that represent the checkpoint positions, c_ic\_i, that Jack jumps to. You are guaranteed that c_1=0c\_1 = 0 and c_i≤106c\_i \leq 10^6

출력

Output a single integer representing the maximum possible jump size such that Jack takes exactly kk jumps through the checkpoints given that jump size. If no such jump size exists, output −1-1.

예제2

  1. 예제 1

    입력
    5 4
    0 2 4 6 7
    
    예상 출력
    2
    
  2. 예제 2

    입력
    5 4
    0 1 2 3 30
    
    예상 출력
    -1