B. Wrath
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Hands that shed innocent blood!

There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person kills the j-th person if and only if j < i and j ≥ i - Li.

You are given lengths of the claws. You need to find the total number of alive people after the bell rings.

Input

The first line contains one integer n (1 ≤ n ≤ 106) — the number of guilty people.

Second line contains n space-separated integers L1, L2, ..., Ln (0 ≤ Li ≤ 109), where Li is the length of the i-th person's claw.

Output

Print one integer — the total number of alive people after the bell rings.

Examples
input
4
0 1 0 10
output
1
input
2
0 0
output
2
input
10
1 1 3 0 0 0 2 1 0 3
output
3
Note

In first sample the last person kills everyone in front of him.

题目大意:n个人排队,第i个人会杀死第j个人当且仅当j < i并且j ≥i-li,问最后有多少个人能幸存下来.

分析:从后往前扫,这样就避免了j<i的干扰,记录一下i-li的最小值,就能判断第j个人是否会被杀死.

时间复杂度O(n).

#include <cstdio>
#include <cmath>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int inf = 0x7fffffff; int n, l[], maxx = inf, ans; int main()
{
scanf("%d", &n);
for (int i = ; i <= n; i++)
scanf("%d", &l[i]);
for (int i = n; i >= ; i--)
{
if (i >= maxx)
ans++;
maxx = min(maxx, i - l[i]);
}
printf("%d\n", n - ans); return ;
}

Codeforces 892 B.Wrath的更多相关文章

  1. codeforces 892 - A/B/C

    题目链接:https://cn.vjudge.net/problem/CodeForces-892A Jafar has n cans of cola. Each can is described b ...

  2. Codeforces 892 C.Pride

    C. Pride time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  3. Codeforces 892 D.Gluttony

    D. Gluttony time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  4. Codeforces 892 A.Greed

    A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  5. codeforces #446 892A Greed 892B Wrath 892C Pride 891B Gluttony

    A  链接:http://codeforces.com/problemset/problem/892/A 签到 #include <iostream> #include <algor ...

  6. Codeforces Round #446 (Div. 2) B. Wrath【模拟/贪心】

    B. Wrath time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  7. 【Codeforces Round #446 (Div. 2) B】Wrath

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 倒着来,维护一个最小的点就可以了. [代码] #include <bits/stdc++.h> using namesp ...

  8. Codeforces Round #446 (Div. 2)

    Codeforces Round #446 (Div. 2) 总体:rating涨了好多,虽然有部分是靠和一些大佬(例如redbag和ShichengXiao)交流的--希望下次能自己做出来2333 ...

  9. CF892.B. Wrath

    ---恢复内容开始--- 题意: 有n个犯人,手上都有个长度为Li的武器,当铃响时大家同时挥动武器,只能把前面攻击范围内的敌人杀死,问最后还剩几个人. 题目传送门: [http://codeforce ...

随机推荐

  1. 机器学习概念之特征处理(Feature processing)

    不多说,直接上干货! 肯定也有不少博友,跟我一样,刚开始接触的时候,会对这三个概念混淆. 以下是,特征处理.特征提取.特征转换和特征选择的区别! 特征处理主要包含三个方面:特征提取.特征转换和特征选择 ...

  2. qconbeijing2017

    http://2017.qconbeijing.com/schedule 第一天 (2017年4月16日/星期日)   签到 专题 主题演讲 快速进化的容器生态 微服务与 DevOps 最佳实践(厂商 ...

  3. 对js 面对对象编程的一些简单的理解

    由简单开始深入: 最简单的 直接对象开始 var desen = { age:24, name:'xyf', job:'fontEnd', getName:function(){ console.lo ...

  4. c#内存管理,垃圾回收和资源释放

    <1>关于虚拟内存的概念 Windows使用一个虚拟寻址系统,该系统把程序可用的内存地址映射到硬件内存中的实际地址上去,这些任务完全由windows后台管理,其实际结果是32位处理机上的每 ...

  5. [BZOJ1045][HAOI2008]糖果传递 数学

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1045 我们假设每一个小朋友的代价为$x[i]$,每一次都从前面一个小朋友那里拿,这种贪心跟 ...

  6. JavaScript创建对象的七种方法

    一. 工厂模式 创建: function createPerson(name,behavior){ var p=new Object(); p.name=name; p.behavior=behavi ...

  7. 从 fn_dbLog 解析操作日志(补充update)

    过去经常听到SQL server 日志,可是在提供的界面上看到的Log不是我们想要的,我们想窥探具体的数据操作日志.专业恢复追踪数据库操作日志的软件:ApexSQLLog,偶然发现SQL Server ...

  8. FPGA内部RAM的初始化

    Altera的RAM初始化文件格式是mif和hex. QuartusII自带的RAM初始化工具很方便产生初始化文件. Xilinx的RAM初始化文件格式是coe, 在vivado中软件会将coe文件变 ...

  9. 在Apache服务器中禁用option

    在apache禁止 http OPTIONS方法. apache disable http OPTIONS method 2013-04-17 09:27 4050人阅读 评论(1) 收藏 举报  分 ...

  10. tac命令

    tac——显示文件内容(反列显示) 命令所在路径:/usr/bin/tac 示例1: # tac /etc/hosts 反列显示/etc/目录下hosts文件内容 ☛适合查看内容较短的文件