#CT0000060. Dãy bền vững (Stable Sequence)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Dãy bền vững (Stable Sequence)
Stable Sequence
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer sequence and an integer . You may delete some elements while preserving the relative order of the remaining elements.
Suppose the kept positions are
The remaining sequence is stable if for every ,
A one-element sequence is always stable. Find the minimum number of deletions.
Input
The first line contains .
The second line contains .
Output
Print the minimum number of elements that must be deleted.
Subtasks
- Subtask 1 (30%): .
- Subtask 2 (20%): .
- Subtask 3 (50%): , , .
Examples
Example 1
Input
6 2
3 5 6 10 11 15
Output
2
Explanation
Keep positions to obtain . It is impossible to delete only one element.
Example 2
Input
5 0
4 1 2 2 5
Output
1
Explanation
Delete the first element; is nondecreasing, exactly the condition for .
Example 3
Input
4 -1
5 3 2 0
Output
2
Explanation
Positions can be kept because . No three positions can be kept.
Liên quan
Trong các cuộc thi sau: