A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly nn minutes. After a round ends, the next round starts immediately. This is repeated over and over again.

Each round has the same scenario. It is described by a sequence of nn numbers: d1,d2,…,dnd1,d2,…,dn (−106≤di≤106−106≤di≤106). The ii-th element means that monster's hp (hit points) changes by the value didi during the ii-th minute of each round. Formally, if before the ii-th minute of a round the monster's hp is hh, then after the ii-th minute it changes to h:=h+dih:=h+di.

The monster's initial hp is HH. It means that before the battle the monster has HH hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 00. Print -1 if the battle continues infinitely.

Input

The first line contains two integers HH and nn (1≤H≤10121≤H≤1012, 1≤n≤2⋅1051≤n≤2⋅105). The second line contains the sequence of integers d1,d2,…,dnd1,d2,…,dn (−106≤di≤106−106≤di≤106), where didi is the value to change monster's hp in the ii-th minute of a round.

Output

Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer kk such that kk is the first minute after which the monster is dead.

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=+;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int t,n,m,k,q;
unsigned long long ans;
ll cnt,flag,temp,sum;
ll h;
int a[N];
int main()
{
cin>>h>>n;
ll H=h;
ll minl=INF;
for(int i=;i<=n;i++){
cin>>a[i];
sum+=a[i];
minl=min(minl,sum);
if(h+sum<=){//如果h加上第一轮的sum小于0,就输出sum值所在下标
cout<<i<<endl;
return ;
}
}
if(minl>=||sum>=){// 和最小序列为正数或一轮所有值的和为正数,输出-1,代表不能实现将hp扣为0及一下
cout<<-<<endl;
return ;
}
cnt=(H+minl)/-sum;//hp加上和最小序列后除-sum得整数轮数,为n-2 或n-1 ,取决于数是到 和最小序列最后一个,还是之前就使hp<=0
if((H+minl)%-sum)//正好最大负值+整数个sum使hp=0
cnt++; //为n-1 或n
ans=(unsigned long long)cnt*n;//轮数乘以每轮个数
h=H+sum*cnt;
if(h<=){ //和最小序列和sum相等,即正好整数个sum使h<=0
cout<<ans<<endl;
return ;
}
for(int i=;i<=n;i++){//累加最后一轮
h+=a[i];
if(h<=){
cout<<ans+i<<endl;
return ;
}
}
}

题意分析:输入一个整数H,代表血量,每一轮的攻击消耗血量或增加血量,求消耗完时是第多少次攻击。

Codeforces1141E(E题)Superhero Battle的更多相关文章

  1. E. Superhero Battle Codeforces Round #547 (Div. 3) 思维题

    E. Superhero Battle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. Codeforces Round #547 (Div. 3) E. Superhero Battle

    E. Superhero Battle A superhero fights with a monster. The battle consists of rounds, each of which ...

  3. CF1141E Superhero Battle

    A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minu ...

  4. E. Superhero Battle

    链接 [https://codeforces.com/contest/1141/problem/E] 题意 怪物开始的生命值,然后第i分钟生命值的变化 问什么时候怪物生命值为非正 分析 有一个巨大的坑 ...

  5. The 2015 China Collegiate Programming Contest -ccpc-c题-The Battle of Chibi(hdu5542)(树状数组,离散化)

    当时比赛时超时了,那时没学过树状数组,也不知道啥叫离散化(貌似好像现在也不懂).百度百科--离散化,把无限空间中无限的个体映射到有限的空间中去,以此提高算法的时空效率. 这道题是dp题,离散化和树状数 ...

  6. 【CF1141E】Superhero Battle

    \[x*p\ge y\rightarrow x=\lfloor{{y-1}\over p}\rfloor+1\]

  7. 【Codeforces 1141E】Superhero Battle

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 二分最后轮了几圈. 二分之后直接o(N)枚举具体要多少时间即可. 注意爆long long的情况. 可以用对数函数,算出来有多少个0 如果大于 ...

  8. 南阳ccpc C题 The Battle of Chibi && hdu5542 The Battle of Chibi (树状数组优化+dp)

    题意: 给你一个长度为n的数组,你需要从中找一个长度为m的严格上升子序列 问你最多能找到多少个 题解: 我们先对原序列从小到大排序,排序之后的序列就是一个上升序列 这里如果两个数相等的话,那么因为题目 ...

  9. 南阳ccpc C题 The Battle of Chibi 树状数组+dp

    题目: Cao Cao made up a big army and was going to invade the whole South China. Yu Zhou was worried ab ...

随机推荐

  1. 牛客网机试题-求root(N,k)

    题目描述     N<k时,root(N,k) = N,否则,root(N,k) = root(N',k).N'为N的k进制表示的各位数字之和.输入x,y,k,输出root(x^y,k)的值 ( ...

  2. Zabbix3.0安装部署最佳实践

    Zabbix介绍 1.1zabbix 简介 Zabbix 是一个高度集成的网络监控解决方案,可以提供企业级的开源分布式监控解决方案,由一个国外的团队持续维护更新,软件可以自由下载使用,运作团队靠提供收 ...

  3. Spring5参考指南:AspectJ注解

    文章目录 什么是AspectJ注解 启用AOP 定义Aspect 定义Pointcut 切入点指示符(PCD) 切入点组合 Advice 访问JoinPoint Advice参数 Advice参数和泛 ...

  4. flex学习

            今天看视频学习的时候,发现css有一个 flex 的属性,非常的好用,为了让自己能够熟记,特意来分享一下flex的用法. 首先,采用Flex布局的元素,称为Flex容器(flex co ...

  5. VMware虚拟机中centos6.5网络配置(桥接方式)与宿主机之间通信

    1.修改网络适配器 2.选择桥接所用的网卡 3.设置网络 3.1在系统终端中输入 setup ,进行图形网络配置(此命令只有redhat系列才有作用) 上下左右键选择,enter键确定 将光标移动到U ...

  6. P6474 [NOI Online #2 入门组] 荆轲刺秦王

    P6474 [NOI Online #2 入门组] 荆轲刺秦王 bfs+差分+卡常 本来我其实是场内选手,但是因为记错提交时间,晚了半小时才交,交不上了,就自动降级为了场外选手 题面复杂,不简述了 首 ...

  7. python ——文件的操作大全,如with..as

    工作中遇到了需要对json文件进行增删内容操作的需要,于是系统性的整理了一下关于文件的基本操作这里的知识点: 结构:新建文件→打开文件→读取文件→关闭文件 一.基本文件操作 1.新建文件(打开文件), ...

  8. xenomai内核解析之xenomai的组成结构

    @ 目录 一.xenomai 3 二.xenomai3 结构 这是第二篇笔记. 一.xenomai 3 从xenomai3开始支持两种方式构建linux实时系统,分别是cobalt 和 mercury ...

  9. thinkphp5.x系列 RCE总结

    Thinkphp  MVC开发模式 执行流程: 首先发起请求->开始路由检测->获取pathinfo信息->路由匹配->开始路由解析->获得模块.控制器.操作方法调度信息 ...

  10. D. Sequence Sorting dp

    D. Sequence Sorting 题目大意:给你一个序列,有一种操作就是对所有相同的数可以挪到最前面,也可以挪到最后面,问最少操作次数. 首先,对于很多个相同的数,可以缩成两个位置,一个是就是这 ...