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. 界面(UI)测试基础

    界面测试,在web程序雏形后就持续测试到项目交付. 项目中的界面测试 此刻需要感慨下“产品经理”的重要性:没有产品把关整个项目,做出来的东西只能叫做“程序”而非“产品” 有产品的工作流,测试在界面测试 ...

  2. 【IntelliJ IDEA】tomcat启动,打印日志乱码问题 【最新解决方法请看最后附录】

    刚开始给idea上配置了一个tomcat,然后跟着http://wiki.jikexueyuan.com/project/intellij-idea-tutorial/theme-settings.h ...

  3. webpack权限控制

    const type= "a"; const menusConfig = { a: ["activity"], b: ["activity" ...

  4. Length of LOB data (190999) to be replicated exceeds configured maximum 65536. 错误修改

    在上传附件时,本地是可以的但服务器上就有了文件大小的限制,不能上传.经过打断点找到这样一个错误: Length of LOB data (190999) to be replicated exceed ...

  5. HTTP缓存总结

    在具体了解 HTTP 缓存之前先来明确几个术语:1.缓存命中率:从缓存中得到数据的请求数与所有请求数的比率.理想状态是越高越好.2.过期内容:超过设置的有效时间,被标记为“陈旧”的内容.通常过期内容不 ...

  6. centos7--web项目使用远程mysql数据库

    07-django项目连接远程mysql数据库   比如电脑a(ip地址为192.168.0.aaa)想要连接访问电脑b(ip地址为192.168.0.bbb)的数据库: 对电脑a(ip地址为192. ...

  7. centos7搭建docker并部署lnmp (转)

      1.首先呢先更新yum源 yum -y update 2.1.安装docker存储库 yum install -y yum-utils \ device-mapper-persistent-dat ...

  8. Invalid property value

    又见这个错误!头几天同事遇到这个问题,我查到去年写的并按此解决了,原文在这里,查了半天,才查出是ftShortInt造成的这个错误. 当我们在设计期将ClientQuery.Active设置为True ...

  9. Html5+Css3小试牛刀

    前因: 我开始做个收款系统,突然客户跑来要插进一个任务,据说他们老板挺在意的,一个小商场,一个首页,一个详情页,UI无自由发挥,要求,尽量好看点. 一番交谈后,确认这是一个对外的网站,最好移动端也能正 ...

  10. ISO/IEC 15444-12 MP4 封装格式标准摘录 3

    目录 Track Data Layout Structures Data Information Box Data Reference Box Sample Size Boxes Compact Sa ...