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 = ;
const int M = ;
const int inf = 0x3f3f3f3f;
const int MOD = ;
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+];
int cmp(ss s1,ss s2) {return s1.p<s2.p;} int main () { scanf("%d",&n);
for(int i=;i<=n;i++) {
scanf("%d%d",&a[i].p,&a[i].s);
a[i].S=a[i].p-a[i].s-;
}
int cnt=; int tmp;
sort(a+,a+n+,cmp);
int ans=,L=;
int cc=;
for(int i=;i<=M;i++) {
if(i==a[cc].p) {
if(a[cc].S>=) {
dp[i] = dp[a[cc].S] +;
}
else dp[i] = ;
cc++;
}
else dp[i] = dp[i-];
ans=max(dp[i],ans);
// cout<<dp[i]<<endl;
}
cout<<n-ans<<endl;
return ;
}

daima

Codeforces Round #336 (Div. 2)C. Chain Reaction DP的更多相关文章

  1. Codeforces Round #336 (Div. 2) 608C Chain Reaction(dp)

    C. Chain Reaction time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  2. Codeforces Round #336 (Div. 2) C. Chain Reaction set维护dp

    C. Chain Reaction 题目连接: http://www.codeforces.com/contest/608/problem/C Description There are n beac ...

  3. Codeforces Round #336 (Div. 1) A - Chain Reaction

    Chain Reaction 题意:有n(1 ≤ n ≤ 100 000) 个灯泡,每个灯泡有一个位置a以及向左照亮的范围b (0 <= a <= 1e6 ,1<= b <= ...

  4. Codeforces Round #336 (Div. 2)B 暴力 C dp D 区间dp

    B. Hamming Distance Sum time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  5. Codeforces Round #336 (Div. 2) D. Zuma 区间dp

    D. Zuma   Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gems ...

  6. Codeforces Round #336 (Div. 2) D. Zuma

    Codeforces Round #336 (Div. 2) D. Zuma 题意:输入一个字符串:每次消去一个回文串,问最少消去的次数为多少? 思路:一般对于可以从中间操作的,一般看成是从头开始(因 ...

  7. Codeforces Round #336 (Div. 2)【A.思维,暴力,B.字符串,暴搜,前缀和,C.暴力,D,区间dp,E,字符串,数学】

    A. Saitama Destroys Hotel time limit per test:1 second memory limit per test:256 megabytes input:sta ...

  8. Codeforces Round #336 (Div. 2)

    水 A - Saitama Destroys Hotel 简单的模拟,小贪心.其实只要求max (ans, t + f); #include <bits/stdc++.h> using n ...

  9. Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)

    题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...

随机推荐

  1. android 下滤镜效果的实现

    android 下滤镜效果的实现 滤镜过滤颜色已实现,简单版本可通过下面代码的3个参数实现黑白.红.绿...等7种过滤(RGB的7种组合). 理论上讲可以过滤为任意颜色.调整混合结果的比值就行了. p ...

  2. mac media server

    近日在mac osx基于开源组件nginx-rtmp-module架设了一台默认的media server,以下是过程笔记 下载https://github.com/arut/nginx-rtmp-m ...

  3. UILabel的相关属性设置

    在iOS编程中UILabel是一个常用的控件,下面分享一下UILabel的相关属性设置的方法. 很多学习iOS6编程都是从storyboard开始,用到UILabel时是将控件拖到storyboard ...

  4. [转]linux中强大的screen命令

    [转]linux中强大的screen命令 http://pythonorg.diandian.com/post/2012-01-05/40027464147 今天用SCREEN用点生了,有几个功能不知 ...

  5. python并行迭代

    并行迭代:同时并行遍历两个列表 for line1,line2 in zip(line1_list, line2_list): ... 无聊,贴一段刚才的代码: import sys import s ...

  6. 使用xilinx ip core FIFO First- World First-Through (FWFT)模式的注意事项

    也许很多人知道xilinx ip core 中的fifo可以配成standard 模式和FWFT模式,并知道两者的区别是:standard模式下,当rd为高时,fifo会延时一个时钟输出数据(时序逻辑 ...

  7. 设计模式之Composite(组合)模式

    1.出现原因 1.在面向对象系统中,我们常会遇到一类具有“容器”特征的对象——即它们在充当对象的同时,又是其他对象的容器. 如何将“客户代码与复杂的对象容器结构”解耦(将这种组合容器对象设计成树形结构 ...

  8. 【收藏】Linux下tomcat内存配置

    常见的内存溢出有以下两种: java.lang.OutOfMemoryError: PermGen space java.lang.OutOfMemoryError: Java heap space ...

  9. sqlserver2008r2 127.0.0.1 用户sa登录失败 错误18456

    按照网上的所有方法都试过了,还是不行. 最后,将sa密码重新设置一下,解决问题.

  10. WEB学习总结 +数据结构

    HTML5  <h1>会员注册界面</h1><form action="process.aspx" method="post" n ...