Chef in Vaccination Queue:
There are N people in the vaccination queue, Chef is standing on the pth position from the front of the queue. It takes X minutes to vaccinate a child and Y minutes to vaccinate an elderly person. Assume Chef is an elderly person.
You are given a binary array A1,A2....AN of length N, where A,=1 denotes there is an elderly person standing on the ith position of the queue, A=0 denotes there is a child standing on the ith position of the queue. You are also given the three integers P,X,Y. Find the number of minutes after which Chef's vaccination will be completed.
Input Format
• The first line contains four space-separated integers N,P,X,Y.
• The second line contains N space-separated integer A1,A2.....AN.
Output Format
Output in a single line the number of minutes after which Chef's vaccination will be completed.
Constraints
• 1≤ N ≤ 100
• 1≤P≤N
• 1 ≤ X,Y ≤ 10
• 0 ≤ A≤1
Ap = 1
Sample Input 1:
4232
0101
Sample Output 1:
5
Explanation:
The person standing at the front of the queue is a child and the next person is Chef. So it takes a total of 3+2=5 minutes to complete
Chef's vaccination.
Sample Input 2:
3123
101
Sample Output 2:
3
Explanation:
Chef is standing at the front of the queue. So his vaccination is completed after 3 minutes.
Sample input E>
4 23 2
0101
Sample output
5
Program:
n, p, x, y = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for i in range(p):
if v[i]:
ans += y
else:
ans += x
print(ans)
0 Comments