# [区间DP][HAOI2011]problem a

``` 1 #include<cstdio>
2 #include<algorithm>
3 using namespace std;
4 const int N=100000+5;
5 int n,m;
6 struct hehe{int l,r,v;}a[N],b[N];
7 bool cmp(hehe x,hehe y)
8  {if(x.r!=y.r) return x.r<y.r;
9   return x.l<y.l;
10  }
11 int f[N];
12 int main()
13  {
14  scanf("%d",&n); int x,y;
15  for(int i=1;i<=n;i++)
16   {scanf("%d%d",&x,&y);
17    a[i].l=x+1; a[i].r=n-y;
18   }
19  sort(a+1,a+n+1,cmp);
20  for(int i=1;i<=n;i++)
21   {if(a[i].l>a[i].r) continue;
22
23    if(a[i].l==b[m].l && a[i].r==b[m].r)
24                 b[m].v=min(b[m].v+1,b[m].r-b[m].l+1);
25
26    else         {b[++m]=a[i]; b[m].v=1;
27                 }
28   }
29  int j=1;
30  for(int i=1;i<=n;i++)
31   {f[i]=f[i-1];
32    while(j<=m && i==b[j].r)
33      {f[i]=max(f[i],f[b[j].l-1]+b[j].v);
34       j++;
35      }
36   }
37  printf("%d",n-f[n]);
38 return 0;
39  }```

```3
2 0
0 2
2 2```

`1`

100%的数据满足： 1≤n≤100000 0≤ai、bi≤n

https://www.luogu.org/problemnew/solution/P2519

[区间DP][HAOI2011]problem a

(0)
(0)