time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

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.

Examples

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 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 position 1337 with power level 42.

【题目链接】:http://codeforces.com/contest/608/problem/C

【题解】



动态规划;

新加的那个塔肯定是毁掉最后面的某个连续的包括最后一个塔的塔的序列;

f[i][0]表示前i个点不被新加的塔攻击到需要毁掉的最少炮塔数目

f[i][1]表示i以及i后面的点都被新加的那个塔毁掉最少需要毁掉的炮塔的数目

f[i][0] = f[j][0]+(i-j-1);

其中aj小于ai-bi且j是最大的;

f[i][1] = f[i-1][1]+n-i+1;

(新加的塔会把后面的n-i+1个塔毁掉)

最后在f[n][0]和f[1..n][1]之间取最小值;前者表示新加的那个塔什么塔都不炸到;后者则相当于枚举它炸到哪个塔;



【完整代码】

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long using namespace std; const int MAXN = 1e5+100;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {0,0,0,-1,1};
const double pi = acos(-1.0); struct abc
{
int a,b;
}; abc c[MAXN];
int n,f[MAXN][2],mi; void rel(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t) && t!='-') t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} void rei(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)&&t!='-') t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} bool cmp(abc a,abc b)
{
return a.a < b.a;
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(n);
for (int i = 1;i <= n;i++)
rei(c[i].a),rei(c[i].b);
sort(c+1,c+1+n,cmp);
f[1][0] = 0;
f[1][1] = n;
for (int i = 2;i <= n;i++)
{
int l = 1,r = i-1,j = 0,judge = c[i].a-c[i].b;
while (l <= r)
{
int m = (l+r)>>1;
if (c[m].a<judge)
j = m,l = m+1;
else
r = m-1;
}
f[i][0] = f[j][0]+(i-j-1);
f[i][1] = f[i-1][0]+n-i+1;
}
mi = f[n][0];
for (int i = 1;i <= n;i++)
mi = min(mi,f[i][1]);
printf("%d\n",mi);
return 0;
}

【33.33%】【codeforces 608C】Chain Reaction的更多相关文章

  1. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  2. 【23.33%】【codeforces 557B】Pasha and Tea

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【33.10%】【codeforces 604C】Alternative Thinking

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【25.33%】【codeforces 552D】Vanya and Triangles

    time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  5. 【33.33%】【codeforces 552B】Vanya and Books

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【33.33%】【codeforces 586D】Phillip and Trains

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【58.33%】【codeforces 747B】Mammoth's Genome Decoding

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【UOJ#33】【UR #2】树上GCD(长链剖分,分块)

    [UOJ#33][UR #2]树上GCD(长链剖分,分块) 题面 UOJ 题解 首先不求恰好,改为求\(i\)的倍数的个数,最后容斥一下就可以解决了. 那么我们考虑枚举一个\(LCA\)位置,在其两棵 ...

  9. JAVA 基础编程练习题33 【程序 33 杨辉三角】

    33 [程序 33 杨辉三角] 题目:打印出杨辉三角形(要求打印出 10 行如下图) 程序分析: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 package ...

随机推荐

  1. 芯片TPS70925

    TPS70925电源芯片 从上图中可以看出EN脚是使能脚,并且是高使能,低失能. tps70925的典型用法: 这个芯片有很多封装,我们用的是第一个:

  2. JS错误记录 - 取消事件冒泡、按钮、回车、ctrl回车提交留言

    window.onload = function () { var oDiv = document.getElementById('div1'); var oBtn = document.getEle ...

  3. 微服务实践(七):从单体式架构迁移到微服务架构 - DockOne.io

    原文:微服务实践(七):从单体式架构迁移到微服务架构 - DockOne.io [编者的话]这是用微服务开发应用系列博客的第七篇也是最后一篇.第一篇中介绍了微服务架构模式,并且讨论了微服架构的优缺点: ...

  4. 搭建聊天机器人Bot Framework

    Bot Framework 搭建聊天机器人 这周我来跟大家分享的是在Microsoft Build 2016上发布的微软聊天机器人的框架. 现如今,各种人工智能充斥在我们的生活里.最典型的人工智能产品 ...

  5. docker基础(二)

    1.base镜像的特点 (1)不依赖于其他的镜像 (2)其它的可以通过它位基础作为容器的底层 2.在下载镜像的时候,只有几百M,但是安装一个Ubuntu虚拟机的镜像就比较大,首先会想到图形化界面,其实 ...

  6. 关于idea新建子目录时往父目录名字后叠加而不是树形结构的解决方法(转)

    我们在IDEA中创建子目录时,子目录总是在父目录后面叠加而不是树形,如下 我们可以打开项目窗口的右上角的设置标志, 将红圈选项的√先去掉,创建好子目录后再将它选中就可以

  7. SpringBoot日志logback-spring.xml分环境(转)

    springboot按照profile进行打印日志 log4j logback slf4j区别? 首先谈到日志,我们可能听过log4j logback slf4j这三个名词,那么它们之间的关系是怎么样 ...

  8. 关于stm32的串口电压问题

    在同一块板子的另一个 2号串口,因为没有使用所以就没有配置,,,所以导致这三个引脚都为0; 上面的串口接口封装是围墙座: 注意:倘若要连线,那时候要记得交叉,当然这也要看各自的设计才行

  9. 怎样推断DIV中的内容为空

    怎样推断DIV中的内容为空 1.问题背景 推断div内部是否为空.假设为空,给出无数据提示:否则显示正常页面 2.设计源代码 <!DOCTYPE html PUBLIC "-//W3C ...

  10. Bash Shell 的管道命令

    1.cut: 命令选取 cut -d'分隔字符' -f fields -d :后面接分隔字符.用-f一起使用 -f: 根据-d的分隔字符将一段信息分割成为数段 -c:以字符的单位取出固定字符区间 Eg ...