#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<int> changes;
main() {
int h, n; cin >> h >> n;
for (int i = 0; i < n*2; i++){
if (i >= n){
changes.push_back(changes[i-n]);
} else {
int g; cin >> g;
changes.push_back(g);
}
}
int s = 0;
for (int i = 0; i < n*2; i++){
s += changes[i];
s = max(s, 0ll);
if (s >= h){
cout << i/n << ' ' << i%n << '\n';
return 0;
}
}
s = accumulate(changes.begin(), changes.end(), 0ll)/2;
if (s <= 0) {
cout << "-1 -1\n";
return 0;
} else {
pair<int, int> d = {1e17, 1e17};
int t = 0;
for (int i = 0; i < n; i++){
t += changes[i]; t = max(t, 0ll);
if (s > 0){
d = min(d, {((h-t)%s==0?(h-t)/s:(h-t)/s+1), i});
}
}
cout << d.first << ' ' << d.second << '\n';
}
}
Compilation message
snail.cpp:5:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
5 | main() {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
748 KB |
Output is correct |
6 |
Correct |
3 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
748 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
748 KB |
Output is correct |
2 |
Correct |
3 ms |
748 KB |
Output is correct |
3 |
Correct |
5 ms |
748 KB |
Output is correct |
4 |
Correct |
5 ms |
768 KB |
Output is correct |
5 |
Correct |
6 ms |
876 KB |
Output is correct |
6 |
Correct |
5 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
748 KB |
Output is correct |
13 |
Correct |
3 ms |
748 KB |
Output is correct |
14 |
Correct |
3 ms |
748 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
456 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
3 ms |
748 KB |
Output is correct |
22 |
Correct |
3 ms |
748 KB |
Output is correct |
23 |
Correct |
5 ms |
748 KB |
Output is correct |
24 |
Correct |
5 ms |
768 KB |
Output is correct |
25 |
Correct |
6 ms |
876 KB |
Output is correct |
26 |
Correct |
5 ms |
748 KB |
Output is correct |
27 |
Correct |
4 ms |
748 KB |
Output is correct |
28 |
Correct |
5 ms |
748 KB |
Output is correct |
29 |
Correct |
4 ms |
748 KB |
Output is correct |
30 |
Correct |
3 ms |
748 KB |
Output is correct |
31 |
Correct |
3 ms |
748 KB |
Output is correct |
32 |
Correct |
3 ms |
748 KB |
Output is correct |