#P11296. Snail Escape
Snail Escape
Snail Escape
A snail is trapped in a well of height \(H\). The snail attempts to escape by climbing in \(N\) stages per day. In stage \(i\) (where \(i\) starts at 0), the snail climbs \(P_i\) meters; note that \(P_i\) can be negative. After each stage, if its height becomes negative, it is reset to 0. The snail escapes the well as soon as its height becomes at least \(H\) (i.e. \(\ge H\)).
Your task is to determine the earliest time (in terms of day and stage) when the snail escapes the well, or report that it is impossible.
Note: Days and stages are 0-indexed. Also, you may need to use a long long
(or the analogue in your chosen language) to store the numbers.
inputFormat
The first line contains two integers \(H\) and \(N\) separated by a space.
The second line contains \(N\) integers \(P_0, P_1, \ldots, P_{N-1}\) separated by spaces.
outputFormat
If the snail can escape the well, output two integers separated by a space: the day number and the stage number on that day when the snail first escapes. If the snail can never escape, output -1
.
sample
10 3
3 2 5
0 2