这一道题目我没有找到原题,所以大家如果找到了原题也麻烦发一下给我,方便我再测评一次。
这一题的意思就是链式反应,等我有机会再来详细的解释,现在先把代码放上来!
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<unordered_map>
#include<queue>
#include<limits>
using namespace std;
int n;
pair<int,int>temp[100005];
vector<int>dp(100005);
int rr(int index)
{
if(dp[index])
return dp[index];
if(index<=0)
return 0;
int ll=temp[index].first-temp[index].second;
int i=lower_bound(temp, temp+index, make_pair(ll,0))-temp-1;
int res=index-1-i;
return dp[index]=res+rr(i);
}
int main()
{
cin>>n;
for(int i=0;i!=n;++i)
{
cin>>temp[i].first>>temp[i].second;
}
sort(temp,temp+n);
//rr(n-2);
int res=INT_MAX;
for(int i=n-1;i>=0;--i)
{
res=min(res,n-1-i+rr(i));
if(res<n-i-i)
break;
}
cout<<res<<endl;
}