301430: CF269B. Greenhouse Effect

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Greenhouse Effect

题意翻译

### 题目大意: 给出 $N$ 个植物,每个植物都属于一个品种,共计 $m$ 个品种,分落在不同的位置上(在一个数轴上,而且数轴是**无限长度**的),保证读入的位置是按照**升序**读入的。 现在我们可以进行一个操作:取任意一个位置上的植物,移动到任意一个没有植物的位子上去。 问我们最少进行多少次操作,能够使得从左到右,是按照**品种升序**排列的($1$ ~ $m$)(**单调不降**),而且每种植物都相邻。

题目描述

Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length. Over the years Emuskald has cultivated $ n $ plants in his greenhouse, of $ m $ different plant species numbered from 1 to $ m $ . His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line. Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange $ m-1 $ borders that would divide the greenhouse into $ m $ sections numbered from 1 to $ m $ from left to right with each section housing a single species. He is free to place the borders, but in the end all of the $ i $ -th species plants must reside in $ i $ -th section from the left. Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders.

输入输出格式

输入格式


The first line of input contains two space-separated integers $ n $ and $ m $ ( $ 1<=n,m<=5000 $ , $ n>=m $ ), the number of plants and the number of different species. Each of the following $ n $ lines contain two space-separated numbers: one integer number $ s_{i} $ ( $ 1<=s_{i}<=m $ ), and one real number $ x_{i} $ ( $ 0<=x_{i}<=10^{9} $ ), the species and position of the $ i $ -th plant. Each $ x_{i} $ will contain no more than 6 digits after the decimal point. It is guaranteed that all $ x_{i} $ are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their $ x_{i} $ coordinates $ (x_{i}&lt;x_{i+1},1<=i&lt;n) $ .

输出格式


Output a single integer — the minimum number of plants to be replanted.

输入输出样例

输入样例 #1

3 2
2 1
1 2.0
1 3.100

输出样例 #1

1

输入样例 #2

3 3
1 5.0
2 5.5
3 6.0

输出样例 #2

0

输入样例 #3

6 3
1 14.284235
2 17.921382
1 20.328172
3 20.842331
1 25.790145
1 27.204125

输出样例 #3

2

说明

In the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1. In the second test case, the species are already in the correct order, so no replanting is needed.

Input

题意翻译

### 题目大意: 给出 $N$ 个植物,每个植物都属于一个品种,共计 $m$ 个品种,分落在不同的位置上(在一个数轴上,而且数轴是**无限长度**的),保证读入的位置是按照**升序**读入的。 现在我们可以进行一个操作:取任意一个位置上的植物,移动到任意一个没有植物的位子上去。 问我们最少进行多少次操作,能够使得从左到右,是按照**品种升序**排列的($1$ ~ $m$)(**单调不降**),而且每种植物都相邻。

加入题单

算法标签: