做法:前缀和

思路:

  • 1.如果前n天(第一轮)不能打死怪物,并且第一轮结束怪物没有掉血可以保证一定打不死怪物
  • 2.剩下的情况可以进行模拟即可

代码

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp(aa,bb) make_pair(aa,bb)
#define _for(i,b) for(int i=(0);i<(b);i++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,b,a) for(int i=(b);i>=(a);i--)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define X first
#define Y second
#define lowbit(a) (a&(-a))
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef long double ld;
const int N=200010;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const double eps=1e-6;
const double PI=acos(-1.0);

ll d[N],s[N];

void solve(){
    ll h;int n;cin>>h>>n;
    ll maxx=INF;
    rep(i,1,n) cin>>d[i],s[i]=s[i-1]+d[i],maxx=min(maxx,s[i]);
    maxx=-maxx;
    int flag=0;
    rep(i,1,n) if(h+s[i]<=0){flag=i;break;}
    if(flag){cout<<flag<<"\n";return;}
    if(!flag&&s[n]>=0){cout<<"-1\n";return;}

    ll day=(h-maxx)/(-s[n]);
    h+=s[n]*day;
    day=day*n;
    while(1){
        rep(i,1,n){
            h+=d[i];day++;
            if(h<=0){
                cout<<day<<"\n";
                return;
            }
        }
    }
}


int main(){
    ios::sync_with_stdio(0);cin.tie(0);
//    int t;cin>>t;while(t--)
    solve();
    return 0;
}