CF607A Chain Reaction
显然的dp,只需要再二分查找一下
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
struct to{
int a;
int b;
friend bool operator <(to x,to y){
return x.a<y.a;
}
}tow[1000005];
int f[1000005];
int a[1000051];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d%d",&tow[i].a,&tow[i].b);
a[i]=tow[i].a;
}
sort(tow+1,tow+n+1);
sort(a+1,a+n+1);
for(int i=1;i<=n;++i){
int ff=lower_bound(a+1,a+n+1,a[i]-tow[i].b)-a-1;
if(ff<=0){
ff=0;
}
f[i]=f[ff]+1;
}
int ans=199999999;
for(int i=1;i<=n;++i){
ans=min(ans,n-f[i]);
}
cout<<ans;
return 0;
}