E. Superhero Battle
链接
[https://codeforces.com/contest/1141/problem/E]
题意
怪物开始的生命值,然后第i分钟生命值的变化
问什么时候怪物生命值为非正
分析
有一个巨大的坑
其实是很简单的一个题
可我还是跳了进去很多次
对于超过n的特别注意就行了
算是经典贪心吧
看代码吧
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e5+10;
ll d[N];
ll sum;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
ll H;
//freopen("in.txt","r",stdin);
while(cin>>H>>n){
sum=0;
ll cur=H,mi=1e17;
bool flag=0;
ll ans;
for(int i=1;i<=n;i++)
{
cin>>d[i]; sum+=d[i];
mi=min(mi,sum);
H+=d[i];
if(!flag&&H<=0) {
ans=i; flag=1;
}
}
if(flag){
cout<<ans<<endl;
}
else if(sum>=0){
cout<<-1<<endl;
}
else{
cur+=mi;
ans=(cur)/(-sum)*n;
ll mo=cur%(-sum);
ll k=mo-mi;
ll cnt=0;
while(k>0){
for(int i=1;i<=n;i++)
{
k+=d[i];
cnt++;
if(k<=0) break;
}
}
//cout<<ans<<' '<<cnt<<endl;
cout<<ans+cnt<<endl;
}
}
return 0;
}