Greenhouse Effect

CodeForces - 269B

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.

Input

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 si (1 ≤ si ≤ m), and one real number xi (0 ≤ xi ≤ 109), the species and position of the i-th plant. Each xi will contain no more than 6 digits after the decimal point.

It is guaranteed that all xi 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 xi coordinates (xi < xi + 1, 1 ≤ i < n).

Output

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

Examples

Input
3 2
2 1
1 2.0
1 3.100
Output
1
Input
3 3
1 5.0
2 5.5
3 6.0
Output
0
Input
6 3
1 14.284235
2 17.921382
1 20.328172
3 20.842331
1 25.790145
1 27.204125
Output
2

sol:题意略坑,按照颜色跑一遍最长不下降子序列就好了
//给出一个实数轴,上面散布着n个点,他们是m种,问最少挪多少步能将数轴上的点分成1~m的种类顺序排列的m块。
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,dp[N];
struct Point
{
int Cor;
double Pos;
}P[N];
int main()
{
int i,j,ans=;
R(n); R(m);
for(i=;i<=n;i++)
{
R(P[i].Cor); scanf("%lf",&P[i].Pos);
}
P[].Cor=; dp[]=;
for(i=;i<=n;i++)
{
for(j=;j<i;j++) if(P[j].Cor<=P[i].Cor) dp[i]=max(dp[i],dp[j]+);
ans=max(ans,dp[i]);
}
Wl(n-ans);
return ;
}
/*
Input
3 2
2 1
1 2.0
1 3.100
Output
1 Input
3 3
1 5.0
2 5.5
3 6.0
Output
0 Input
6 3
1 14.284235
2 17.921382
1 20.328172
3 20.842331
1 25.790145
1 27.204125
Output
2 Input
15 5
4 6.039627
2 7.255149
2 14.469785
2 15.108572
4 22.570081
5 26.642253
5 32.129202
5 44.288220
5 53.231909
5 60.548042
4 62.386581
2 77.828816
1 87.998512
3 96.163559
2 99.412872
Output
6
*/
 

codeforces269B的更多相关文章

随机推荐

  1. 怎样在 Vue 中使用 事件修饰符 ?

    Vue 中可以通过 v-on 来绑定事件监听函数, 不过事件会有许多额外情况, 比如 是否阻止冒泡 / 是否阻止重载 / 是否限制点击次数 / 是否可以通过按键触发 等等. 这时就需要使用到 事件修饰 ...

  2. 进阶Java编程(6)正则表达式

    正则表达式 通过之前一系列的分析可以发现,String是一个非常万能的类型,因为String不仅仅可以支持有各种字符串的处理操作,也支持有向各个数据类型的转换功能,所以在项目的开发之中,只要用户输入的 ...

  3. (转载)项目中表、类、包、JSP命名规范

    对于Java(包括在jsp中)的代码,类名一律用pascal标记法,每个单词的头个字母大写:参数,方法一律用camel标记法,首字母是小写的,能不缩写的都不缩写! 项目名 = 数据库名         ...

  4. asp.net 9 ViewState

    VIEWSTATE aspx: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind=&quo ...

  5. TypeError: this.setDynamic is not a function

    启动项目npm run serve 报错 Module build failed (from ./node_modules/_babel-loader@8.0.6@babel-loader/lib/i ...

  6. Django单元测试 相关知识

    前言 本文,旨在说明python Django如何编写单元测试,从“背景”,“测试要求”,“代码编写”,“如何运行”,“检验测试覆盖度” 这几个方面来说明附上django的官方文档单元测试章节=> ...

  7. 在STM32上如果不使用外部晶振,OSC_IN和OSC_OUT的接法

    如果使用内部RC振荡器而不使用外部晶振,请按照下面方法处理: 1)对于100脚或144脚的产品,OSC_IN应接地,OSC_OUT应悬空.2)对于少于100脚的产品,有2种接法:  2.1)OSC_I ...

  8. Some notes of The Peter Principle

    管理学读书笔记之彼得原理 chapter0 绪论为什么有这么多不称职现象?姑息错误或纵容懒惰.偶然事故都不是问题根源,关键是我们的社会为不称职现象提供土壤,并对其有所鼓励. chapter1 彼得原理 ...

  9. 陌上花开 HYSBZ - 3262 (CDQ分治)

    陌上花开 HYSBZ - 3262 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),用三个整数表示. 现在要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量. 定义一朵花A比另 ...

  10. zencart设置特价商品价格

    登录后台-工具-安装SQL脚本(Install SQL Patches) 运行以下语句: , '0001-01-01'); 红色部分请替换成实际要设置的数据:1234表示产品ID,888表示特价.