标签:ace sum 位置 name mat names bit std 题目
#include<bits/stdc++.h>
#define ll long long
#define FOR(i,n) for(int i =1; i <= n;++i )
#define FOR0(i,n) for(int i =0; i < n;++i )
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 2*1e6+10;
ll H;
int n;
int a[maxn];
int main(){
cin >>H >> n;
ll tot = 0;
ll mps = 0;
ll HH = H;
FOR(i,n){
cin >> a[i];
tot += a[i];
HH+= a[i];
mps = min(mps,tot);
a[i+n] = a[i];
if(HH<=0){
cout <<i << endl;
exit(0);
}
}
if(tot >=0){
cout << -1 << endl;
}else{
ll len = H/(-1*tot);
len = max(len-mps/tot,0LL);
H+=len*tot;
len *= n;
while(H>0){
FOR(i,n+n){
H+= a[i];
if(H<=0){
len += i;
break;
}
}
if(H>0)
len += n+n;
}
cout << len<<endl;
}
return 0;
}
被卡了两次,贪心也不能贪过头了
Codeforces 1141E Superhero Battle
标签:ace sum 位置 name mat names bit std 题目
原文地址:https://www.cnblogs.com/xxrlz/p/11223780.html