The Captain's Room

  • + 1 comment

    Enter your code here. Read input from STDIN. Print output to STDOUT

    k=int(input()) list_k=list(map(int,input().split()))

    Use set to get the unique value in the list

    room_set = set(list_k)

    now we are multiplying sum of the set with k first

    then we are subtracting it with the original list's sum (so that only the captains value*(k-1) remains)

    then we are dividing by (k-1) to get the actual value

    captain_room = (sum(room_set)*k - sum(list_k)) // (k-1)

    print(captain_room)