PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000120. Chia dãy theo hiệu lớn nhất (Partition Array Such That Maximum Difference Is K)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chia dãy theo hiệu lớn nhất (Partition Array Such That Maximum Difference Is K)
Partition Array Such That Maximum Difference Is K
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given nonnegative integers and nonnegative , partition all elements into the minimum number of nonempty groups. Each element belongs to one group; original order does not matter. In each group, maximum minus minimum must not exceed .
Input
The first line contains . The next line contains integers .
Output
Print the minimum number of valid groups.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
5 2
3 6 1 2 5
Output
2
Explanation
Groups and meet the difference limit, while one group would have difference .