Houses needed to feed the rats
There are R rats and each needs U units of food. Houses are visited in order and each holds some food. Print the smallest number of houses (from the first) whose food together is enough for all the rats. If all houses together are not enough, print 0.
Reported in: Accenture (Aug 2022) (memory-based)
Input
Line 1: R. Line 2: U. Line 3: N. Line 4: food in each of the N houses.
Output
The number of houses, or 0.
Constraints
1 ≤ N ≤ 10^5.
Example 1
Input:
7
2
8
2 8 3 5 7 4 1 2
Output:
4Example 2
Input:
5
3
3
1 2 3
Output:
0Hint: Need = R × U. Add house food one by one until the total reaches the need.