Find The Fine

Last updated: 29th Aug, 2020

  

Problem Statment

Given an array of penalties P , an array of car numbers C, and also the date D. The task is to find the total fine which will be collected on the given date. Fine is collected from odd-numbered cars on even dates and vice versa.



Example 1:

Input
2
4 12
2375 7682 2325 2352
250 500 350 200
3 8
2222 2223 2224
200 300 400

Output:
600
300

Method:

  • Check the Date
  • Update the Sum of Penalties of Even Car Numbers and Update the Sum of Odd Car Numbers.
  • If its Odd,Print Sum of Penalties of Even Car Number
  • Else,Print Sum of Penalties of Odd Car Numbers

Python Code

t = int(input())
for c in range(t):
    n,d=input().split()
    car_num=[int(x) for x in input().split( )]
    fine =[int(y) for y in input().split( )]
    amount=0
    if (int(d)%2==0):
        for i in range(len(car_num)):
            if (car_num[i]%2!=0):
                amount+=fine[i]
                                              
    else:
        for i in range(len(car_num)):
            if(car_num[i]%2==0):
                amount+=fine[i]
    print(amount)