There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated.
Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed.
The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the initial number of beacons.
The i-th of next n lines contains two integers ai and bi (0 ≤ ai ≤ 1 000 000, 1 ≤ bi ≤ 1 000 000) — the position and power level of thei-th beacon respectively. No two beacons will have the same position, so ai ≠ aj if i ≠ j.
Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added.
4 1 9 3 1 6 1 7 4
1
7 1 1 2 1 3 1 4 1 5 1 6 1 7 1
3
For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position1337 with power level 42.
题意:给出n个灯塔的坐标(仅在x轴上)和此灯塔能够向左照射的范围当打开此灯塔所有在此灯塔范围内的灯塔都会被毁灭可以在最右边加上一个灯塔坐标和攻击范围任定然后从右向左依次打开灯塔问最少能够毁灭的灯塔数。dp
/* ***********************************************
Author : ryc
Created Time : 2016-08-21 Sunday
File Name : E:\acm\codeforces\336C.cpp
Language : c++
Copyright 2016 ryc All Rights Reserved
************************************************ */
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<list>
#include<stack>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int,int>pii;
const int maxn=1000010;
int dp[maxn];
int num[maxn];
int main()
{
int n,a,b;cin>>n;
for(int i=1;i<=n;++i){
scanf("%d%d",&a,&b);
num[a]=b;
}
int ans=0;
for(int i=0;i<maxn;++i){
if(num[i]){
dp[i]=1;
int x=i-num[i]-1;
if(x>=0)dp[i]+=dp[x];
ans=max(ans,dp[i]);
}
else if(i){
dp[i]=dp[i-1];
}
}
printf("%d\n",n-ans);
return 0;
}