先贴代码,明天再写吧……
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
ll shu[100000+10];
int main(){
int t;
scanf("%d",&t);
while(t--){
ll n,m;
scanf("%lld%lld",&n,&m);
ll sum = 0;
ll now = 0;
ll Max = 0;
ll ans = -1;
for(int i=0;i<n;i++){
scanf("%lld",&shu[i]);
sum += shu[i];
}
for(int j=0;j<2;j++){
if(ans != -1) break;
for(int i=0;i<n;i++){
now += shu[i];
Max = max(Max,now);
if(now<0) now = 0;
if(now>=m) break;
}
if(now>=m) ans = j+1;
}
if(sum>0 && ans==-1){
ans = 2+(m-Max+sum-1)/sum;
}
cout << ans << endl;
}
return 0;
}