This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int O = 2e5 + 5;
const int base = O;
int n, h, Max, sum, p[O];
main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> h >> n;
for (int i = 1; i <= n; ++ i){
cin >> p[i];
sum += p[i];
Max = max(Max, sum);
}
if (Max < h && sum <= 0) return cout << "-1 -1", 0;
if (Max >= h){
cout << 0 << " ";
sum = 0;
for (int i = 1; i <= n; ++ i){
sum += p[i];
if (sum >= h){
cout << i - 1;
break;
}
}
return 0;
}
int l = 0, r = 1e12;
while (l <= r){
int mid = (l + r) / 2;
/// bo len duoc vao ngay mid
if (max(0ll, (mid - 1)) * sum + Max >= h) r = mid - 1;
else l = mid + 1;
}
r = max(0ll, r);
cout << r << " ";
sum *= r;
for (int i = 1; i <= n; ++ i){
sum += p[i];
if (sum >= h) return cout << i - 1, 0;
}
}
/***
9 12
8
7
-13
7
9
-6
-12
-10
-6
-7
-12
-11
***/
Compilation message (stderr)
snail.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
11 | main(){
| ^~~~
# | 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... |