Haunted Halloween!


Submit solution

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

You are marching down a street of \(N\) houses on Halloween night.
Each house either gives or takes candies:

  • If the value is positive, you gain that many candies.
  • If the value is negative, you lose that many candies.

You start with \(0\) candies.
You can hold at most \(K\) candies (extra candies are discarded).
If your candies ever drop below the haunting threshold \(H\), you run home immediately and stop visiting houses.

Determine:

  1. How many houses you visited before stopping.
  2. How many candies you had at that moment.

Note that the number of candies you have can be negative!

Input Specification

The first line contains three integers \(N\), \(K\), and \(H\)
\((1 ≤ N, K ≤ 1000, -100 ≤ H ≤ 100)\).

The second line contains N space-separated integers \(A[i]\) \((-100 ≤ A[i] ≤ 100)\), representing the candy change at each house.

Output Specification

Print two integers separated by a space: the number of houses visited, and the number of candies you collected before you ran away.

Sample Input 1

7 10 0
3 4 -2 5 -8 6 2

Sample Output 1

7 10

Sample Input 2

3 3 -1
4 -5 6

Sample Output 2

2 -2

Explanation:
You visit house \(1\), getting \(4\) candy. But you can only keep \(3\). So you end up with \(3\) candy.
Onto house \(2\): you lose \(5\) candy, meaning that you now have \(-2\) candy. This is below \(-1\) so you become frightened and run away!
You've only visited \(2\) homes and ended with \(-2\) candy, which is the output.


Comments

There are no comments at the moment.