You are viewing a single comment's thread. Return to all comments →
k=int(input()) list_k=list(map(int,input().split()))
room_set = set(list_k)
captain_room = (sum(room_set)*k - sum(list_k)) // (k-1)
print(captain_room)
Seems like cookies are disabled on this browser, please enable them to open this website
The Captain's Room
You are viewing a single comment's thread. Return to all comments →
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)