CSES - Last number

You are given a list that contains nn integers.

Consider a process, where at each step you find the two smallest integers on the list, remove both from the list, and add the sum of the two numbers minus one to the end of the list. This continues until the list contains only a single number. What is this number?

Your task is to create an efficient algorithm that determines that last number for a given list. The time complexity of the algorithm should be O(n)O(n).

In a file lastnumber.py, implement a function find that returns the desired number.

def find(t):
    # TODO

if __name__ == "__main__":
    print(find([1,2,3,4])) # 7
    print(find([1,1,1])) # 1
    print(find([5,1,1,7,9,1,2])) # 20

Explanation: Given the list [1,2,3,4][1,2,3,4], you first remove the numbers 11 and 22 and add the number 22. Now the list is [3,4,2][3,4,2]. Then you remove the numbers 33 and 22 and add the number 44, obtaining the list [4,4][4,4]. Finally, you remove the numbers 44 and 44 and add the number 77, obtaining the list [7][7].