[2016-02-04][CF][545C][Woodcutters]

Woodcutters

Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u

Submit Status

Description

Little Susie listens to fairy tales before bed every day. Today‘s fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.

There are n trees located along the road at points with coordinates x1,?x2,?...,?xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi?-?hi,?xi] or [xi;xi?+?hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn‘t contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.

Input

The first line contains integer n (1?≤?n?≤?105) — the number of trees.

Next n lines contain pairs of integers xi,?hi (1?≤?xi,?hi?≤?109) — the coordinate and the height of the ?-th tree.

The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate.

Output

Print a single number — the maximum number of trees that you can cut down by the given rules.

Sample Input

Input

51 22 15 1010 919 1

Output

3

Input

51 22 15 1010 920 1

Output

4

Hint

In the first sample you can fell the trees like that:

  • fell the 1-st tree to the left — now it occupies segment [?-?1;1]
  • fell the 2-nd tree to the right — now it occupies segment [2;3]
  • leave the 3-rd tree — it occupies point 5
  • leave the 4-th tree — it occupies point 10
  • fell the 5-th tree to the right — now it occupies segment [19;20]

In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

#include<cstdio>

#include<algorithm>

#include<vector>

#include<cstring>

using namespace std;

const int maxn = 1E5 + 10;

pair<int,int> m[maxn];

int main(){

    int n,x,h;

    scanf("%d",&n);

    for(int i = 0; i < n ; i++){

        scanf("%d%d",&x,&h);

        m[i] = make_pair(x,h);

    }

    if(n == 1)

    {

        printf("1\n");

        return 0;

    }

    int pre = m[0].first;

    int res = 2;

    for(int i = 1 ;i < n - 1;i++)

    {

        x = m[i].first;

        h = m[i].second;

        int next = m[i+1].first;

        if( x - h > pre )

        {

            res++;

            pre = x;

        }

        else if( x + h < next){

            res++;

            pre = x + h;

        }else pre = x;

    }

    printf("%d\n",res);

    return 0;

}

来自为知笔记(Wiz)

时间: 2024-08-09 00:29:00

[2016-02-04][CF][545C][Woodcutters]的相关文章

CF 545C Woodcutters(贪心)

题目链接:http://codeforces.com/problemset/problem/545/C 题目: Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the

2016/02/21 codes

var Class = { create:function(){ var parent = null,properties = $A(arguments); if(Object.isFunction(properties[0])) parent = properties.shift(); function kclass(){ this.initialize.apply(this.arguments); } Object.extend(kclass,Class.Methods); kclass.s

FFMpeg ver 20160219-git-98a0053 滤镜中英文对照 2016.02.21 by 1CM

FFMpeg ver 20160219-git-98a0053 滤镜中英文对照 2016.02.21 by 1CM T.. = Timeline support 支持时间轴 .S. = Slice threading 分段线程 ..C = Command support 支持命令传送 A = Audio input/output 音频 输入/输出 V = Video input/output 视频 输入/输出 N = Dynamic number and/or type of input/out

Oracle数据库创建与安装_超越OCP精通Oracle视频教程培训02~04

_超越OCP精通Oracle视频教程培训02~04 学完本Oracle视频教程能掌握以下内容: Oracle数据库相关概念/体系结构/物理结构/逻辑结构 Oracle数据库GRID组件与ASM存储概念 VMware虚拟机的安装与主机环境的配置 Windows2008 Server操作系统安装 Linux操作系统安装与基本配置 Windows/Linux操作系统Oracle 11g数据库软件的安装 Windows/Linux操作系统Oracle 11g数据库的创建 Linux上Oracle11g基

2016年04月MVP开始申请了~[截止时间:1月12日]

51CTO与微软中国合作长期为用户提供申请"微软最有价值专家"的平台希望有兴趣.资历的朋友以及正在朝这个方向努力的朋友能够积极参与只要您想参与我们将为您向微软推荐 微软最有价值专家MVP一年评选4次分别为每年的1月.4月.7月.10月.2016年4月的MVP申请截止时间是2016年1月12日. 申请MVP的午饭请下载2016年4月MVP申请表填好后发送到[email protected].我们会在每次MVP申请开始时把用户提交的申请表格推荐到微软中国相关部门 [注意事项]1.51CTO

2016/02/20 codes

<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>2016/02/20</title></head><body><div id="mainDiv"> <div id = "content"> <div id = &qu

分布式技术一周技术动态 2016.02.21

分布式系统实践 1. 远程接口设计经验分享 http://mp.weixin.qq.com/s?__biz=MzAwNjQwNzU2NQ%3D%3D&idx=2&mid=402064901&scene=0&sn=0b5f56a97b431ed355b75a9e17f2e754 要点: 分布式系统由于中间存在网络因素, 出错的情况比单机系统要多很多, 那么如何设计一个远程接口呢? 本文很好的解释了设计远程接口需要考虑的问题点. 2. 时序列数据库武斗大会之什么是TSDB ht

2016年04月29日【EPM-易通元】最新价位公布

2016年04月29日[EPM-易通元]最新价位公布   涨了.涨了.又涨了!   我们的「EPM易通元」天天见涨!太给力了!!   2016.04.29日今天已涨0,01美金,目前已到0.35美金啦!   如果你有1000个易通元,你今天就收益10美金   如果你有10000个易通元,今天就收益100美金   如果你有100000个易通元,你今天就收益1000美金.   恭喜买到「EPM易通元」的朋友们,买到即是赚到!   买入210美金到3500美金 :1美金:6.3人民币兑换,举例买入35

2016/02/16 codes

<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>2016/02/16 codes</title> <link rel="stylesheet" href="assets/reset.css"> <style> .slideOne{ width: