-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathfind_the_fine.cpp
40 lines (36 loc) · 1006 Bytes
/
find_the_fine.cpp
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
// https://practice.geeksforgeeks.org/problems/find-the-fine/0/?company[]=Microsoft&problemStatus=unsolved&page=1&query=company[]MicrosoftproblemStatusunsolvedpage1
#include <bits/stdc++.h>
using namespace std;
void solve_test()
{
int number_cars, date, i;
cin >> number_cars >> date;
int cars[number_cars];
int penalities[number_cars];
for(i=0; i < number_cars; i++)
cin >> cars[i];
for(i=0; i < number_cars; i++)
cin >> penalities[i];
// Fine is collected from odd-numbered cars on even dates and vice versa.
long int total = 0;
for(i=0; i < number_cars; i++)
{
if(cars[i] % 2 !=0 && date % 2 == 0)
total += penalities[i];
else if(cars[i] % 2 ==0 && date % 2!= 0)
total += penalities[i];
}
cout <<total<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long int t;
cin >> t;
while(t--)
{
solve_test();
}
return 0;
}