• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

CodeforcesRound#336(Div.2)C.ChainReactionDP

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
C. Chain Reaction
 

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.

Input

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 the i-th beacon respectively. No two beacons will have the same position, so ai ≠ aj if i ≠ j.

Output

Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added.

Sample test(s)
input
4
1 9
3 1
6 1
7 4
output
1
input
7
1 1
2 1
3 1
4 1
5 1
6 1
7 1
output
3
Note

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 9with 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个灯,每个灯在ai有一个威力值bi, 开启它,使得左边与其距离小于等于 bi 的会损坏

      现在给你一个机会  可以在最右端 放一个 任意位置任意威力值的灯,并且从最右端的灯开始开启  问你最少的损坏的灯个数是多少

题解:设DP[i] 表示从1到i的这段距离内 不会损坏的 灯个数是多少

    因为我们是开启灯 灯就不会损坏   

  dp[i] = dp[a[cnt]-b[cnt]-1] + 1;  (1<=cnt<=n);

//meek///#include<bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<iostream>
#include<bitset>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll;

const int N = 201000;
const int M = 1000001;
const int inf = 0x3f3f3f3f;
const int MOD = 100003;
const double eps = 0.000001;

struct ss{
  int p,s,S;
}a[N];
int n,b[N],H[N],t[M],sum[N],dp[M+5];
int cmp(ss s1,ss s2) {return s1.p<s2.p;}

int main () {

    scanf("%d",&n);
    for(int i=1;i<=n;i++) {
        scanf("%d%d",&a[i].p,&a[i].s);
        a[i].S=a[i].p-a[i].s-1;
    }
    int cnt=0;   int tmp;
    sort(a+1,a+n+1,cmp);
   int ans=0,L=0;
    int cc=1;
    for(int i=0;i<=M;i++) {
         if(i==a[cc].p) {
            if(a[cc].S>=0) {
                dp[i] = dp[a[cc].S] +1;
            }
            else dp[i] = 1;
            cc++;
         }
         else dp[i] = dp[i-1];
         ans=max(dp[i],ans);
        // cout<<dp[i]<<endl;
    }
    cout<<n-ans<<endl;
    return 0;
}
daima

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
[转]C#将image中的显示的图片转换成二进制发布时间:2022-07-18
下一篇:
C#简单入门发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap