#P11296. [NOISG 2018 Prelim] Snail

[NOISG 2018 Prelim] Snail

Background

Translated from NOISG 2018 Prelim A. Snail.

Problem Description

A snail is trapped in a well of height HH.

The snail keeps trying to climb out of the well. Specifically, in one day the snail goes through NN stages. In stage ii, it climbs PiP_i meters toward the top of the well (can be negative). When the snail’s height is greater than or equal to the height of the well opening, it leaves the well. When the snail’s height is less than 00, its height is considered to be 00.

You are asked to find the earliest time when the snail leaves the well, or report that there is no solution.

Note that both days and stages are 0-indexed, meaning the first stage is actually stage 00. Also, you may need to use long long to store the input numbers.

Input Format

The first line contains two integers H,NH, N. The next line contains NN integers, where the ii-th integer represents PiP_i.

Output Format

Output one line with two integers D,PD, P, meaning the snail leaves the well on day DD at stage PP. If it can never leave, output -1 -1.

3 1
1
2 0
5 1
-1
-1 -1
5 2
4 -2
1 0

Hint

Sample #1 Explanation

At stage 00 on day 00, it climbs 11 meter, reaching a total height of 11 meter.

At stage 00 on day 11, it climbs 11 meter, reaching a total height of 22 meters.

At stage 00 on day 22, it climbs 11 meter, reaching a total height of 33 meters, and leaves the well.

Sample #2 Explanation

Clearly, the snail can never leave.

Constraints

Subtask Score Special Properties
00 Samples
11 1111 N=1N = 1
22 99 All PiP_i are the same
33 2525 H×N104H\times N \leq 10^4
44 1717 Pi0P_i\geq0
55 3838 None

For 100%100\% of the testdata: $1 \leq H \leq 10^{12}, -10^{12}\leq P_i\leq 10^{12}, 1\leq N \leq 10^4$.

Translated by ChatGPT 5