Help me in solving MAXIMISESUM problem

My issue

why am i getting time limit exceeded

My code

# cook your dish here
def equal(a):
    return all(element==a[0] for element in a)
t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    rea=equal(a)
    if rea==True:
        print(sum(a))
    else:
        for i in range(n):
            a.sort()
            max2=a[-2]
            mul=(n-1)*max2
        print(mul+a[-1])

Problem Link: MAXIMISESUM Problem - CodeChef

@bhavyapeesa
inside for loop of n ,u r sorting which will take nlogn time .
thus the overall complexity will n^2log(n).
U need to optimize your solution .
Hint :- use prefix and suffix logic.