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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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 , 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: . Second line: integers .
Output
Print the minimum capability.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
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.