Problem:


Score: 400 points

Problem Statement

Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i.

The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere.

When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0.

What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?

Constraints

All values in input are integers.

2 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the maximum total comfort the N players can get.

Sample Input 1

4
2 2 1 3

Sample Output 1

7

By arriving at the place in the order Player 4, 2, 1, 3, and cutting into the circle as shown in the figure, they can get the total comfort of 7.

They cannot get the total comfort greater than 7, so the answer is 7.

Sample Input 2

7
1 1 1 1 1 1 1

Sample Output 2

6



Sample input:
4
2 2 1 3


Sample output:
7

Submission status: Wrong Answer

Solution code:
import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

# available on Google, not available on Codeforces
# import numpy as np
# import scipy


def solve(lst):  # fix inputs here
    console("----- solving ------")
    lst = sorted(lst)[::-1]

    res = lst[0]
    # print(lst)

    for i in range(len(lst)-2):
        res += min(lst[i], lst[i+1])
        # print(res)

    # return a string (i.e. not a list or matrix)
    return res


def console(*args):  # the judge will not read these print statement
    print('\033[36m', *args, '\033[0m', file=sys.stderr)
    return


for case_num in [1]:
    # read line as a string
    # strr = input()

    # read line as an integer
    k = int(input())
    
    # read one line and parse each word as a string
    # lst = input().split()

    # read one line and parse each word as an integer
    lst = list(map(int,input().split()))

    # read matrix and parse as integers (after reading read nrows)
    # lst = list(map(int,input().split()))
    # nrows = lst[0]  # index containing information, please change
    # grid = []
    # for _ in range(nrows):
    #     grid.append(list(map(int,input().split())))

    res = solve(lst)  # please change
    
    # Google - case number required
    # print("Case #{}: {}".format(case_num+1, res))

    # Codeforces - no case number required
    print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))

A.sort()
print(sum(A) - A[0])

Submission status: Wrong Answer

Solution code:
#D
N=int(input())
A=sorted(list(map(int,input().split())))[::-1]
ans=0
#print(A)

from collections import deque
C=deque([A[0]])

for i in range(1,N):
    if i%2==1:
        C.append(A[i])
        ans+=min(C[-2],C[0])
        
    else:
        C.appendleft(A[i])
        ans+=min(C[1],C[-1])
    
    #print(C)
    #print(ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
a.sort()
b=a.pop(-1)
if n%2==0:
    print(sum(a[-(n-2)//2:])*2+b)
elif n==3:
    print(b+a[-1])
elif n==5:
    print(b+a[-1]*2)
elif n%2==1:
    print(sum(a[-(n-2)//2+1:])*2+b+a[-(n-2)//2])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = sorted(A, reverse=True)
x = 0
for i in range (len(B) -1 ):
  x = x + B[i]
print(x)

Submission status: Wrong Answer

Solution code:
def main():

    N = int(input())
    A = list(map(int, input().split()))

    v = A[0]
    if (N-2) % 2 == 0:
        v += sum(A[1:1+(N-2)//2]) * 2
        print('here')
    else:
        v += sum(A[1:1+(N-2)//2]) * 2 + A[1+(N-2)//2]
    return v

if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = 0
a.sort(reverse = True)
s = sum(a[:-1])
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()

ans = 0

for i in range(1, N):
  ans += A[i]

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
A.sort()
print(sum(A[1:]))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np

def main():
	n=II()
	A=LI()
	A.sort(reverse=True)

	ans=A[0]
	ans+=2*sum(A[1:(n+1)//2-1])

	if n%2:
		ans+=A[n//2]
	else:
		ans+=2*A[(n-1)//2]

	print(ans)











if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=1000000001
s=0
for i in range(n):
    s=s+a[i]
    m=min(m,a[i])
print(s-m)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse = True)

print(sum(A) - A[-1])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

N = int(input())
A = sorted(list(map(int, input().split())))[::-1]

print(sum(A[:-1]))

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
from decimal import Decimal
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def num_divisors_table(n):
    table = [0 for i in range(n + 1)]
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table

# ここから書き始める
n = int(input())
a = list(map(int, input().split()))

ans = sum(a) - min(a)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)
kei = 0
for i in range(1, N):
    kei += A[i - 1]
print(kei)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	A = inputList()

	A.sort()
	A = A[::-1]
	ans = 0
	maxs = 0
	nexts = A[1]

	for i,val in enumerate(A):
		if i == 0:
			maxs = val
			continue
		if i == 1:
			ans += maxs
		else:
			ans += nexts

	print(ans)




#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n=int(input())
print(sum(sorted(list(map(int,input().split())))[1:]))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
a = min(l)
b = 0
for i in range(n):
  b = b + l[i]
print(b-a)

Submission status: Wrong Answer

Solution code:
N = int(input())
AA= list(map(int,input().split()))
AA.sort(reverse=True)
ccurrent = AA.pop(0)
conf = 0
for a in AA:
  conf+=ccurrent
  ccurrent = a
print(conf)

Submission status: Wrong Answer

Solution code:
n = int(input())-2
A = list(map(int,input().split()))
A.sort(reverse=True)
ans = A[0]
for i in range(n//2):
    ans += 2*A[i+1]
if n%2 != 0:
    ans += A[n//2]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li_a = list(map(int, input().split()))
li_a.sort()
print(sum(li_a)-li_a[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))

A.sort()
print(sum(A)-A[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
a.pop()
print(sum(a))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    cnt = 1
    ans = A[0]
    flag = False
    for i in range(1,N):
        if cnt + 1 == N - 1:
            ans += A[i]
            break
        ans += A[i] * 2
        cnt += 2
        if cnt == N - 1:
            break

    print(ans)
    


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import heapq

n=int(input())
a=[-int(x) for x in input().split()]

heapq.heapify(a)
ans=0

while True:
    temp=heapq.heappop(a)
    if len(a)==0:
        break
    ans+=temp

print(-ans)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = sorted(LIST(), reverse=True)

ans = 0
for i in range(1,n):
    if i == 1:
        ans += a[0]
    elif i == 2:
        ans += a[1]
    else:
        ans += a[i-2]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int,input().split()))
 
lst.sort()
in_list = []
in_list.append(lst[n-1])
sum = 0
lst = lst[:-1]
for i in range(n-1):
  in_list.sort()
  sum += in_list[0]
  in_list.append(lst[len(lst)-1])
  lst = lst[:-1]
  
print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))

ans = sum(A) - min(A)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
X = A.pop()
counter = 0
for i in range(N-1):
  counter += X
  X = A.pop()
  
print(counter)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
a=a[1:]
print(sum(a))

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
print(sum(L)-min(L))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
res = 0
for i in range(1, N):
    if i == 1:
        res += A[i-1]
        continue
    res += min(A[i-1], A[i-2])
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
print(sum(A[:-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
lol=[int(n) for n in input().split()]
x=max(lol)
lol.remove(x)
y = max(lol)
ans = x + (n-2)*y
print(ans)

Submission status: Wrong Answer

Solution code:
a=int(input())
lists=list(map(int,input().split()))
lists.sort()
print(sum(lists)-lists[0])

Submission status: Wrong Answer

Solution code:
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
point = 0
point += A[0]

cnt = 1
for a in A[1:]:
    for _ in range(2):
        point += a
        cnt += 1
        if cnt == N-1:
            break
    if cnt == N-1:
        break

print(point)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))

A = sorted(A, reverse=True)

circle = [A[0], A[1]]

sum = A[0]

for a in A[2:]:
    if circle[-2] > circle[-1]:
        sum += circle[-1]
    else:
        sum += circle[-2]
    circle.append(a)

print(sum)

Submission status: Wrong Answer

Solution code:
def main():
  n = int(input())
  a = list(map(int,input().split()))
  a.sort(reverse=True)
  ans=0
  for i in range(1,n):
    ans+=a[i-1]
  print(ans)

main()

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
l = sorted(l, reverse=True)

Min = 3
ans = 0
for i in range(1, n):
  ans += Min
  Min = l[i]
  
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

A = list(map(int, input().split()))
A.sort(reverse=True)

ans = 0
cur = 0
for i in range(N - 1):
    ans += A[cur]
    if i < 2:
        cur += 1
    elif i % 2 == 1:
        cur += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
N=int(input())
A=list(map(int,input().split()))
A.sort()
lst=deque()
lst.append(A.pop())
c=0
count=0
while A:
    B=A.pop()
    c+=min(lst[0],lst[-1])
    if count%2==0:
        lst.append(B)
    else:
        lst.appendleft(B)
    count+=1
print(c)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
import collections, heapq, itertools, bisect
import math, fractions
import sys, copy

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline().rstrip())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    N = I()
    A = sorted(LI(), reverse=True)
    q = []
    ans = A[0]
    q.append((-min(A[0], A[1]), A[0], A[1]))
    q.append((-min(A[0], A[1]), A[0], A[1]))

    for i in range(2, N):
        (minus_x, left, right) = q.pop()
        ans += -minus_x
        q.append((-min(left, A[i]), left, A[i]))
        q.append((-min(right, A[i]), A[i], right))

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
n=int(input())
li=deque(list(map(int,input().split())))
m=max(li)
deque.remove(li,m)
ans=m
for i in range(len(li)-1):
    m=max(li)
    ans+=m
    deque.remove(li,m)
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input())
data = list(map(int, input().split()))
data.sort(reverse=True)

q = []
heapq.heappush(q, data[1])
heapq.heappush(q, data[1])
result = data[0]

for i in range(2, n):
    result += heapq.heappop(q)
    heapq.heappush(q, data[i])
    heapq.heappush(q, data[i])

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

ans = 0
for i in range(n-1):
  ans += a[i]
  
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int, input().split()))
l.sort()
l.reverse()
s = l[0]
for i in range(N-2):
  s = s + min(l[i],l[i+1])
print(s)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	A = inputList()

	A.sort()
	A = A[::-1]
	ans = 0
	maxs = 0

	for i,val in enumerate(A):
		ans += val

	print(ans-A[-1])




#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)

print(sum(A)-A[N-1])

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input())
data = list(map(int, input().split()))
data.sort(reverse=True)

q = []
heapq.heappush(q, data[0])
heapq.heappush(q, data[1])
result = data[0]

for i in range(2, n):
    result += heapq.heappop(q)
    heapq.heappush(q, data[i])
    heapq.heappush(q, data[i])

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
strlist = list(map(int, input().split()))
intlist = [int(x) for x in strlist]
sortlist = sorted(intlist)

sortlist.pop(0)
ans = 0

for d in sortlist:
  ans += int(d)

print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort(reverse=True)
    print(sum(A[:N-1]))

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np

def main():
	n=II()
	A=LI()
	A.sort(reverse=True)

	ans=A[0]
	ans+=2*sum(A[1:(n+1)//2-1])

	if n%2:
		ans+=A[n//2]

	print(ans)











if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = 0
for i in range(n-1):
    ans += a[i]
print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    N = I()
    A = LI()
    a = sorted(A, reverse=True)

    print(sum(a[:N-1]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
a.sort()
b=a.pop(-1)
if n%2==0:
    print(sum(a[-(n-2)//2:])*2+b)
if n%2==1:
    print(sum(a[-(n-2)//2+1:])*2+b+a[-(n-2)//2])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
c = n - 2
ans = a[0]
idx = 1
while c > 0:
	ans += a[idx] * min(c,2)
	idx += min(c,2)
	c -= min(c,2)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = list(map(int,input().split()))
A.sort()
B = A[1:]
print(sum(B))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
print(sum(A)-min(A))

Submission status: Wrong Answer

Solution code:
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from decimal import Decimal 		# a = Decimal(a)	# use this for math questions
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
4
2 2 1 3
'''

def solve(l):
	n = len(l)
	l.sort(reverse=True)
	ans = 0
	for i in range(1,n):
		if(i == 1):
			ans += l[0]
		else:
			ans += min(l[i-1],l[i-2])
	return ans
	

N = int(stdin.readline())
l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l)
print(ans)

Submission status: Wrong Answer

Solution code:
#D - Chat in a Circle
N = int(input())
A= list(map(int,input().split()))
A.sort(reverse =True)
#print(A)
ans = sum(A[:-1])
print(ans)

Submission status: Wrong Answer

Solution code:
def d_chat_in_a_circle():
    N = int(input())
    A = sorted([int(i) for i in input().split()], reverse=True)
    return sum(A[i - 1] for i in range(1, N))

print(d_chat_in_a_circle())

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

a.sort()

print(sum(a)-a[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = sum(A) - A[-1]
print(ans)

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
a.sort()
b=a.pop(-1)
if n%2==0:
    print(sum(a[-(n-2)//2:])*2+b)
if n%2==1:
    print(sum(a[-(n-2)//2+1:])*2+b+a[-(n-2)//2+1])

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n = int(input())
a = [int(x) for x in input().split()]
a.sort()
a = a[::-1]
ans = sum(a[:n - 2])
print(ans + a[1])

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
gaps = [-A[0]]
ans = 0
for a in A[1:]:
    x = heappop(gaps)
    ans += -x
    heappush(gaps, -a)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
q = list(map(int,input().split()))
c = []
ans = 0
q.sort()
for i in range(N-1):
    c.append(q[-1])
    q.pop(-1)
    ans += c[i]
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))

d  = sorted(a, reverse = True)
print(sum(d) - d[n-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)

ans = 0

if N%2 == 0:
    ans = 2*sum(A[:N//2]) - A[0]
else:
    ans = 2*sum(A[:(N//2+1)]) - A[0] - A[(N//2+1)]
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

def main():
    N = int(input())
    A = list(map(int, input().split()))

    min = 10 << 10
    res = 0

    for i in range(N):
        res += A[i]
        if min > A[i]:
            min = A[i]
    
    print(res - min)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int, input().split())))

print(sum(a[1:]))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=0
for i in range(N):
  if i!=N-1:
    ans+=A[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
b = sorted(a,reverse = True)

print(sum(b)-b[-1])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
A.reverse()
count=0
for i in range(N-1):
    count+=A[i]
print(count)

Submission status: Wrong Answer

Solution code:
from heapq import *

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

r = 0
Q = [A[0]]
for v in A[1:]:
	c = heappop(Q)
	r += c
	heappush(Q, v)
	heappush(Q, v)

print(r)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
B = A[1:]
print(sum(B))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split())) 
new_a = sorted(a)
b = sum(new_a) - new_a[0]
print(b)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
print(sum(A) - min(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(int(x) for x in input().split())
A.sort(reverse=True)
if n == 2:
    print(A[0])

ans = A[0]
for i in range(2, n):
    ans += A[i//2]
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	A = inputList()

	A.sort()
	A = A[::-1]
	ans = 0
	maxs = 0

	for i,val in enumerate(A):
		if i == 0:
			maxs = val
			continue
		ans += maxs
		maxs = val


	print(ans)




#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
N = int(input())

A = input()
A = [int(i) for i in A.split(" ")]

print(sum(A) - min(A))