Fair Share

Fair Share 

Problem Statement: 

Raju and Kumar are friends and they order S items in a hotel but Kumar does not eat the Ith item ordered. Raju eats the Ith item alone. They decide to share the cost of all items they share and eat. The amount paid by Kumar is also passed as the input. If the bill amount is split equally after deducting the Ith item price the program must print "FAIR SHARE" otherwise the program must print the absolute difference between amount paid by Kumar and the half of the amount for the items shared by Raju and Kumar. Input Format: First line contains S & I [S - Number of Items & I - the item ate by Raju alone]. Second line contains items cost separated by space. Third line contains the amount paid by Kumar Output Format: First Line contains "FAIR SHARE" or the absolute difference between the amount paid by Kumar and the half of the amount for the items shared by Raju and Kumar rounded up to 1 decimal place. 

Example Input/Output 1: 

Input: 

7 4 

12 3 7 34 12 4 8 

30 

Output: 

7.0 

Example Input/Output 2: 

Input: 

5 3 

40 20 11 6 8 

37 

Output: 

FAIR SHARE 

Example Input/Output 3: 

Input: 

4 4 

15 10 20 25 

25 

Output: 

2.5

Program:

s,i = map(int,input().split())

l = list(map(int,input().split()))

kumar = int(input())

ith_amount = l[i-1] 

l.remove(ith_amount)

if sum(l)//2 == kumar:

    print("FAIR SHARE")

else: 

    diff = abs(kumar-(sum(l))/2) 

    print(diff)

Comments

Popular posts from this blog

Pronic Integers in N - InfyTQ question

Count Strong Points - Accenture

Letters at position of multiples of a number