Coatless in Yakutsk

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

요약
코트를 C일마다 세탁해야 할 때, 세탁 일정을 정해 코트 없이 지내는 날의 최저 기온을 최대한 높이는 값을 구한다.
난이도

보통10점 중 7점

유형
동적 계획법, 그리디, 이분 탐색
정답자
아직 제출이 없습니다

문제

It was your first time visiting Salvador, and you made the rookie mistake of sleeping on the beach. You woke up red, sunburned, and frankly, humiliated. Swearing vengeance against the sun and all its terrible consequences, you decided that your next vacation would be somewhere with a real winter – like Yakutsk, Russia, where the average temperature is −42∘−42^\circ Celsius.

But you came prepared! You brought a warm, cozy coat. The coat is perfect, it warms you very well. Maybe too well, as you get sweaty and the coat gets dirty after CC days of use. Since your trip lasts more than CC days, you must find a way to avoid walking around smelling bad.

To do so, when the coat gets dirty, you cannot wear it until it is washed, but you may also choose to wash it earlier. On any day you do not wear the coat – whether because it is dirty or being washed – you must endure the day’s temperature without its protection. After being washed, the coat is fresh and ready to be worn again. At the start of your trip, the coat is clean.

Given the daily temperatures in Yakutsk for the duration of your trip, you must determine the lowest temperature on a day when you are forced to be without your coat, assuming you schedule wash days optimally to make this temperature as high as possible.

입력

The first line contains two integers CC and NN (1≤C<N≤1051 ≤ C < N ≤ 10^5), indicating respectively the number of days you can wear the coat before it gets dirty, and the duration in days of your holidays.

The second line contains NN integers T_1,T_2,…,T_NT\_1, T\_2, \dots , T\_N (−50≤T_i≤50−50 ≤ T\_i ≤ 50 for i=1,2,…,Ni = 1, 2, \dots , N), where T_iT\_i is the temperature on the ii-th day.

출력

Output a single line with an integer indicating the minimum temperature you must endure without your coat.

예제1

  1. 예제 1

    입력
    2 6
    -20 -10 -5 -10 -2 -40
    
    예상 출력
    -5