You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** 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.
2
+
3
+
You are given a binary array A1,A2,…,AN of length N, where Ai=1 denotes there is an elderly person standing on the ith position of the queue, Ai=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.
4
+
5
+
Input Format
6
+
First line will contain T, number of testcases. Then the testcases follow.
7
+
The first line of each test case contains four space-separated integers N,P,X,Y.
8
+
The second line of each test case contains N space-separated integer A1,A2,…,AN.
9
+
Output Format
10
+
For each testcase, output in a single line the number of minutes after which Chef's vaccination will be completed.**/
11
+
12
+
importjava.util.*;
13
+
publicclassvaccination_queue
14
+
{
15
+
publicstaticvoidmain(Stringargs[]) //main function
16
+
{
17
+
Scannerin = newScanner (System.in);
18
+
intt = in.nextInt(); // taking variable t for no. of test cases
19
+
while(t>0)
20
+
{
21
+
intn = in.nextInt(); //n = No.of people
22
+
intp = in.nextInt(); //p = Position of chef from front of the queue
23
+
intx = in.nextInt(); //x = Minutes taken to vaccinate a child
24
+
inty = in.nextInt(); //y = Minutes taken to vaccinate an elder
25
+
intcountc =0; //Counter that counts no of child present ahead of chef.
26
+
intcounta =0; //Counter that counts no of elder present ahead of chef.
27
+
intarr[] = newint[n]; //Array to store the position of people statnding in line.
28
+
//Loop For storing position of people where 1 stands for elder person and 0 stands for child.
29
+
for(inti =0;i<n;i++)
30
+
{
31
+
arr[i] = in.nextInt();
32
+
}
33
+
//Loop to count all the children and elder person ahead of chef including the chef
34
+
for(intj =0;j<p;j++)
35
+
{
36
+
if(arr[j]==0) //checking if the person is child then incrementing the counter
37
+
{
38
+
countc++;
39
+
}
40
+
if(arr[j]==1) //checking if the person is elder then incrementing the counter
41
+
{
42
+
counta++;
43
+
}
44
+
45
+
}
46
+
inttmin = (countc*x)+(counta*y); //Calculating the total time taken by multiplying with the x and y given.
47
+
System.out.println(tmin); //printing the result
48
+
49
+
50
+
51
+
t--; //decrementing the value after running a testcase.
0 commit comments