Sleeping on the Train

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

요약
안토니오가 깨어난 구간 기록이 주어질 때, 정류장 a에서 b로 가는 동안 열차가 방향을 바꾼 최소 횟수를 구한다.
난이도

보통10점 중 7점

유형
그리디, 구현, 수학
정답자
아직 제출이 없습니다

문제

Antonio is sightseeing in Line Town. Part of his sightseeing involves taking the famous Line Train. The Line Train goes through nn stops conveniently numbered from 11 to nn. The path the Line Train takes involves starting at stop 11, then going to every stop in numerically increasing order until it reaches stop nn, at which point it turns around and goes to every stop in numerically decreasing order until it reaches stop 11, where it turns around and repeats its journey. When the train gets to either stop 11 or stop nn, it lets all passengers that want to disembark leave the train. It then turns around, and then allows new passengers to board before heading to the next stop.

Antonio is traveling from stop aa to stop bb. Antonio is very sleepy, so he is not paying attention when he boards the train and could board a train initially heading in the wrong direction. Immediately upon boarding the train, he falls asleep and wakes up tt times during the trip. Each time he wakes up, he notices that he is somewhere between stop s_is\_i and s_i+1s\_i+1. Since he is very sleepy, he does not know which direction the train is traveling in. Also, since he is not presently at his destination, he immediately falls back asleep.

After the ttht^\text{th} time waking up, Antonio decides he should stay awake for the rest of the trip. He stays on the train until the next time it stops at stop bb, at which point he disembarks.

Compute the minimum number of times the train turned around while he was on it.

입력

The first line contains four integers, nn (2≤n≤109)(2 \le n \le 10^9), tt (1≤t≤105)(1 \le t \le 10^5), aa, and bb (1≤a,b≤n,a≠b1 \le a, b \le n, a \neq b).

The second line contains tt integers. The ithi^\text{th} integer, s_is\_i (1≤s_i<n)(1 \le s\_i < n), indicates that when Antonio woke up for the ithi^\text{th} time, he was somewhere between stops s_is\_i and s_i+1s\_i+1.

출력

Output the minimum number of times the train turned around while he was on it.

예제2

  1. 예제 1

    입력
    10 1 5 3
    4
    
    예상 출력
    0
    
  2. 예제 2

    입력
    10 2 5 3
    5 4
    
    예상 출력
    1