-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.rats_sufficient_food
40 lines (38 loc) · 1.27 KB
/
11.rats_sufficient_food
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""11. rats suffiecient food
The function accepts two positive integers ‘r’ and ‘unit’ and a positive integer array ‘arr’ of size ‘n’ as its argument ‘r’ represents the number of rats present in an area, ‘unit’ is the amount of food each rat consumes and each ith element of array ‘arr’ represents the amount of food present in ‘i+1’ house number, where 0 <= i.
Note:
1. Return -1 if the array is null
2. Return 0 if the total amount of food from all houses is not sufficient for all the rats.
3.Computed values lie within the integer range.
Example:
Input:
r:7
unit: 2
n:8 arr:28357412
Output:
4
Explanation:
Total amount of food required for all rats = r unit
=72=14.
The amount of food in 1st houses = 2+8+3+5 = 18. Since, the amount of food in 1st 4 houses is sufficient for all the rats. Thus, output is 4.
"""
no_of_rats=int(input())
units=int(input())
n=int(input())
arr=list(map(int,input().split(" ")))
#no_of_rats=7
#units=2
#n=8
#arr=[2,8,3,5,7,4,1,2]
house_count,summation_value=0,0
if len(arr)==0:
print(-1)
else:
for i in range(0,n):
house_count+=1
summation_value+=arr[i]
if(summation_value>=no_of_rats*units):
print(house_count)
break
if(summation_value<no_of_rats*units):
print(0)