PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000344. Năng lực chọn nhà nhỏ nhất (House Robber IV)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Năng lực chọn nhà nhỏ nhất (House Robber IV)

House Robber IV

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Choose at least k houses from a row of n houses with values aia_i, without choosing adjacent houses. The capability of a selection is its largest chosen value. Minimize the capability. A feasible selection always exists.

Input

First line: n,kn,k. Second line: nn integers aia_i.

Output

Print the minimum capability.

Subtasks

  • Subtask 1 (20 points): 1≤n≤151\le n\le15; 1≤k≤⌊(n+1)/2⌋1\le k\le\lfloor(n+1)/2\rfloor; 1≤ai≤1091\le a_i\le10^9.
  • Subtask 2 (30 points): 1≤n≤1051\le n\le10^5; k=1k=1; 1≤ai≤1091\le a_i\le10^9.
  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; 1≤k≤⌊(n+1)/2⌋1\le k\le\lfloor(n+1)/2\rfloor; 1≤ai≤1091\le a_i\le10^9.

Examples

Input 1

4 2
2 3 5 9

Output 1

5

Explanation

Choose houses 1 and 3. Under threshold 4, at most one of the first two can be selected.

Input 2

5 2
2 7 9 3 1

Output 2

2

Explanation

Choose houses 1 and 5; threshold 1 allows only house 5.