#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
const int MOD = 1e9 + 7;
const int INF = 1e13;
const int N = 1e6;
int n, m, k, a, b, c, d, h, l, r, q, u, v, x, y;
vector<int> arr(N);
void solve() {
cin >> h >> n;
d = 0;
x = 0;
a=-1;
b=-1;
for(int i = 0; i<n; i++) {
cin >> arr[i];
d += arr[i];
x = max(x, d);
if(d>=h && a==-1) {
a = 0;
b = i;
}
}
if(a!=-1) {
cout << a << " " << b;
return;
}
if(d<=0) {
cout << -1 << " " << -1;
return;
}
l = ceil((h - x)/d) + 1;
r = 0;
while(r<l-1) {
m = r + (l-r)/2;
if(m-1 >= (h-x)/d + (((h-x)%d)>0)) l = m;
else r = m;
}
c = d*(l-1);
for(int i = 0; i<n; i++) {
c += arr[i];
if(c>=h) {
cout << l-1 << " " << i;
return;
}
}
}
int32_t main() {
ios::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int tc = 1;
// cin >> tc;
while(tc--) {
solve();
cout << "\n";
}
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... |