今日不写日感,直接扔上今日兴趣点:

新研究称火星曾经有一个巨大的地下水系统

链接:https://mbd.baidu.com/newspage/data/landingsuper?context=%7B"nid"%3A"news_6959868648919860397"%7D&n_type=0&p_from=1

------------------------------------------------题目----------------------------------------------------------

Heaters

Vova's house is an array consisting of nn elements (yeah, this is the first problem, I think, where someone lives in the array). There are heaters in some positions of the array. The ii-th element of the array is 11 if there is a heater in the position ii, otherwise the ii-th element of the array is 00.

Each heater has a value rr (rr is the same for all heaters). This value means that the heater at the position pospos can warm up all the elements in range [pos−r+1;pos+r−1][pos−r+1;pos+r−1].

Vova likes to walk through his house while he thinks, and he hates cold positions of his house. Vova wants to switch some of his heaters on in such a way that each element of his house will be warmed up by at least one heater.

Vova's target is to warm up the whole house (all the elements of the array), i.e. if n=6n=6, r=2r=2 and heaters are at positions 22 and 55, then Vova can warm up the whole house if he switches all the heaters in the house on (then the first 33 elements will be warmed up by the first heater and the last 33 elements will be warmed up by the second heater).

Initially, all the heaters are off.

But from the other hand, Vova didn't like to pay much for the electricity. So he wants to switch the minimum number of heaters on in such a way that each element of his house is warmed up by at least one heater.

Your task is to find this number of heaters or say that it is impossible to warm up the whole house.

Input

The first line of the input contains two integers nn and rr (1≤n,r≤10001≤n,r≤1000) — the number of elements in the array and the value of heaters.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤10≤ai≤1) — the Vova's house description.

Output

Print one integer — the minimum number of heaters needed to warm up the whole house or -1 if it is impossible to do it.

Examples

input

     

output

 

input

    

output

 

input

    

output

-

input

         

output

 

Note

In the first example the heater at the position 22 warms up elements [1;3][1;3], the heater at the position 33 warms up elements [2,4][2,4] and the heater at the position 66 warms up elements [5;6][5;6] so the answer is 33.

In the second example the heater at the position 11 warms up elements [1;3][1;3] and the heater at the position 55 warms up elements [3;5][3;5] so the answer is 22.

In the third example there are no heaters so the answer is -1.

In the fourth example the heater at the position 33 warms up elements [1;5][1;5], the heater at the position 66 warms up elements [4;8][4;8] and the heater at the position 1010 warms up elements [8;10][8;10] so the answer is 33.

------------------------------------------------题目----------------------------------------------------------

(一) 原题大意:

  有n个位置顺序排列。可以在某些位置放置灯光。假设x位置放置了一个灯光,这样位置在[x-r+1,x+r-1]范围内的所有位置都可以被灯光的光辉照亮

  所有位置都想要被照亮,请问要至少多少个灯?

  注:无解的话输出-1。

  输入的第一行包含两个整数n和r(1≤n,r≤1000) - 位置的个数和灯光光线半径。

  第二行包含n个整数a1,a2,...,(0≤ai≤1) - ai=1代表该位置可以放灯光,但不一定有必要。

  最后打印一个整数 - 至少要放的灯光个数,如果不可能照亮所有位置,则为-1。

『ACM C++』 Codeforces | 1066B - Heaters的更多相关文章

  1. 『ACM C++』 Codeforces | 1066A - Points in Segments

    大一生活真 特么 ”丰富多彩“ ,多彩到我要忙到哭泣,身为班长,很多班级的事情需要管理,也是,什么东西都得体验学一学,从学生会主席.团委团总支.社团社长都体验过一番了,现在差个班长也没试过,就来体验了 ...

  2. 『ACM C++』 Codeforces | 1005D - Polycarp and Div 3

    今天佛了,魔鬼周一,在线教学,有点小累,但还好,今天AC了一道,每日一道,还好达成目标,还以为今天完不成了,最近任务越来越多,如何高效完成该好好思考一下了~最重要的还是学业的复习和预习. 今日兴趣新闻 ...

  3. 『ACM C++』 Codeforces | 1003C - Intense Heat

    今日兴趣新闻: NASA 研制最强推进器,加速度可达每秒 40 公里,飞火星全靠它 链接:https://mbd.baidu.com/newspage/data/landingsuper?contex ...

  4. 『ACM C++』 PTA 天梯赛练习集L1 | 007-011

    真的是忙头晕了,学业.ACM打题.班级活动.自学新东西,哇这充实的大学~ ------------------------------------------------L1-007--------- ...

  5. 『ACM C++』HDU杭电OJ | 1418 - 抱歉 (拓扑学:多面体欧拉定理引申)

    呕,大一下学期的第一周结束啦,一周过的挺快也挺多出乎意料的事情的~ 随之而来各种各样的任务也来了,嘛毕竟是大学嘛,有点上进心的人多多少少都会接到不少任务的,忙也正常啦~端正心态 开心面对就好啦~ 今天 ...

  6. 『ACM C++』HDU杭电OJ | 1425 - sort (排序函数的特殊应用)

    今天真的是累哭了,周一课从早八点半一直上到晚九点半,整个人要虚脱的感觉,因为时间不太够鸭所以就回头看看找了一些比较有知识点的题来总结总结分析一下,明天有空了就开始继续打题,嘻嘻嘻. 今日兴趣电影: & ...

  7. 『ACM C++』HDU杭电OJ | 1415 - Jugs (灌水定理引申)

    今天总算开学了,当了班长就是麻烦,明明自己没买书却要带着一波人去领书,那能怎么办呢,只能说我善人心肠哈哈哈,不过我脑子里突然浮起一个念头,大二还要不要继续当这个班委呢,既然已经体验过就可以适当放下了吧 ...

  8. 『ACM C++』Virtual Judge | 两道基础题 - The Architect Omar && Malek and Summer Semester

    这几天一直在宿舍跑PY模型,学校的ACM寒假集训我也没去成,来学校的时候已经18号了,突然加进去也就上一天然后排位赛了,没学什么就去打怕是要被虐成渣,今天开学前一天,看到最后有一场大的排位赛,就上去试 ...

  9. 『ACM C++』PTA浙大 | 基础题 - 打印沙漏

    <数据结构>开课前的一些小作业练习,可能因为一个寒假都没有打C++手生了,整个寒假都在帮拍电影做后期特效,导致这道题居然用了两个钟去AC,深感惭愧,作个标记吧,下面上题. 一首好曲推荐:同 ...

随机推荐

  1. sass(@at-root与&配合使用、without和with)

    @at-root与&配合使用(找父级) scss.style css.style 应用于@keyframe scss.style css.style @at-root (without: .. ...

  2. order by MetadataToken解决反射字段顺序问题

    public class Person { public string 姓名{get;set;} } public class Profile:Person { public string 档案号{g ...

  3. CentOS7 下安装 SublimeText3

    原文地址:http://www.sundabao.com/centos-%E5%AE%89%E8%A3%85sublime-text-3/ Centos 安装Sublime text 3 Centos ...

  4. OpenCV 小图重叠至大图指定位置

    Android OpenCV Java: Codes: smallImg.copyTo( bigImg.submat( y, smallImg.rows(), x, smallImg.cols() ) ...

  5. Android DB类,支持MDB,SQLITE,SQLSERVER,支持查询、事务,对象直接插入和更新操作等

    直做数据库,最近花了点时间把自己常用的东西封装在一起. DBHelper using System; using System.Collections.Generic; using System.Te ...

  6. Python爬虫教程-25-数据提取-BeautifulSoup4(三)

    Python爬虫教程-25-数据提取-BeautifulSoup4(三) 本篇介绍 BeautifulSoup 中的 css 选择器 css 选择器 使用 soup.select 返回一个列表 通过标 ...

  7. configure配置安装详解

    使用 ./configure --help 就可以查看到所有的配置选项. 1.--host=HOST指定软件运行的系统平台.如果没有指定,将会运行`config.guess'来检测.--host 指定 ...

  8. 2 (自我拓展)部署花的识别模型(学习tensorflow实战google深度学习框架)

    kaggle竞赛的inception模型已经能够提取图像很好的特征,后续训练出一个针对当前图片数据的全连接层,进行花的识别和分类.这里见书即可,不再赘述. 书中使用google参加Kaggle竞赛的i ...

  9. Javascript 删除tr 元素

    Javascript 删除tr 元素   function delete1(obj){ var tr=obj.parentNode.parentNode; var tbody=tr.parentNod ...

  10. 关于单一网络适配器拓扑TMG

    单网络适配器拓扑的功能 在单网络适配器拓扑中可以实现有限的 Forefront TMG 功能,其中包括: 针对 HTTP.HTTPS 和 CERN 代理 FTP 的正向 (CERN) 代理(仅限下载) ...