#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a[10004], n;
bool experiment(){
ll tong=0, tong2=0;
for(ll i=0; i<n; i++){
tong+=a[i];
if(tong<0) tong=0;
}
tong2=tong;
for(ll i=0; i<n; i++){
tong2+=a[i];
if(tong2<0) tong2=0;
}
if(tong==tong2) return true;
else return false;
}
ll H, i, j, t, num, x, h_max=0, tong;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>H>>n;
for(i=0; i<n; i++){ cin>>a[i]; x+=a[i]; h_max=max(h_max, x);}
if(experiment()==true){
t=0;
while(t<2){
for(i=0; i<n; i++){
tong+=a[i];
if(tong<0) tong=0;
else if(tong>=H){ cout<<t<<' '<<i; return 0; }
}
t++;
} cout<<"-1 -1";
}
else{
//cout<<"yess"<<endl;
tong=0;
for(i=0; i<n; i++){
tong+=a[i];
if(tong>=H){ cout<<0<<' '<<i; return 0; }
if(tong<0) tong=0;
}
num=(H-tong-h_max)/x;
num-=2;
num=max(num , 0LL);
tong+=num*x;
while(true){
num++;
for(i=0; i<n; i++){
tong+=a[i];
if(tong>H){
cout<<num<<' '<<i;
return 0;
}
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |