#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
snail.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
11 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Incorrect |
0 ms |
208 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Incorrect |
0 ms |
208 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Incorrect |
1 ms |
464 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Incorrect |
0 ms |
208 KB |
Output isn't correct |