//#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 H, n, i, j, a[10004], tong, tong1, h_max, t=0, day=0, x, tongkq;
int main(){
cin>>H>>n;
for(i=0; i<n; i++){
cin>>a[i];
tong1+=a[i];
if(tong1<0) tong1=0;
tong+=a[i];
h_max=max(h_max, tong);
}
day=0;
t=0;
while(day<2){
for(i=0; i<n; i++){
t+=a[i];
// cout<<t<<' ';
if(t<0) t=0;
if(t>=H){
cout<<day<<' '<<i;
return 0;
}
}
day++;
}
if(tong<=0) cout<<"-1 -1";
else{
// cout<<"yess"<<endl;
x=(H-tong1-h_max)/tong;
x=max(x, 0LL);
tongkq+=tong1+tong*x;
while(true){
for(i=0; i<n; i++){
tongkq+=a[i];
if(tongkq>=H){
cout<<x+1<<' '<<i;
return 0;
}
}
x++;
}
}
}
# | 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... |