Chef in Vaccination Queue Problem Code: VACCINQSubmit
There are people in the vaccination queue, Chef is standing on the position from the front of the queue. It takes minutes to vaccinate a child and minutes to vaccinate an elderly person. Assume Chef is an elderly person.
You are given a binary array of length , where denotes there is an elderly person standing on the position of the queue, denotes there is a child standing on the position of the queue. You are also given the three integers . Find the number of minutes after which Chef's vaccination will be completed.
Input Format
- First line will contain , number of testcases. Then the testcases follow.
- The first line of each test case contains four space-separated integers .
- The second line of each test case contains space-separated integer .
Output Format
For each testcase, output in a single line the number of minutes after which Chef's vaccination will be completed.
Constraints
Sample Input 1
3
4 2 3 2
0 1 0 1
3 1 2 3
1 0 1
3 3 2 2
1 1 1
Sample Output 1
5
3
6
Explanation
Test case : The person standing at the front of the queue is a child and the next person is Chef. So it takes a total of minutes to complete Chef's vaccination.
Test case : Chef is standing at the front of the queue. So his vaccination is completed after minutes.
Test case : Chef is standing at the rear of the queue. So it takes a total of minutes to complete Chef's vaccination.
solution in c++
#include<iostream>
#include<algorithm>
using namespace std;
class solution
{
public:
void solve()
{
int n, p, x, y;
cin >> n >> p >> x >> y;
int* arr = new int[n];
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
int total = 0;
for (int i = 0; i < p; i++)
{
if (arr[i] == 1)
total += y;
else
total += x;
}
cout << total << "\n";
}
};
int main()
{
solution ss;
int t;
cin >> t;
while (t--)
{
ss.solve();
}
return 0;
}
No comments:
Post a Comment