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:
n = int(input())

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

ans = a[0]

cnt = 1
i = 1
while cnt < n-1:
    cnt += 2
    ans += a[i] * 2
    i += 1

if cnt == n:
    ans -= a[i]

print(ans)

Submission status: Wrong Answer

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

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:
import heapq as hq

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

a.sort()
p = a.pop()
q = []
hq.heappush(q, (-p, -p))
ans = 0
for _ in range(n - 1):
    p = a.pop()
    b1, b2 = hq.heappop(q)
    print(b1, b2)
    ans += -b1
    hq.heappush(q, sorted((b1, -p), reverse=True))
    hq.heappush(q, sorted((b2, -p), reverse=True))
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq as hq

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

a.sort()
p = a.pop()
q = []
hq.heappush(q, (-p, -p))
ans = 0
for _ in range(n - 1):
    p = a.pop()
    b1, b2 = hq.heappop(q)
    ans += -b2
    hq.heappush(q, sorted((b1, -p)))
    hq.heappush(q, sorted((b2, -p)))
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

input = stdin.readline

N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
res  = a[0]
cnt = N - 2
cur = 1
while cnt:
    if cnt == 1:
        res += a[cur]
        break
    else:
        res += a[cur] * 2
        cnt -= 2

print(res)

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(map(int, input().split()))

a.sort(reverse=True)

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

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(N-1):
  S += A[N-i-1]
print(S)

Submission status: Wrong Answer

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

for i in range(N):
  S += A[N-i-1]
print(S)

Submission status: Wrong Answer

Solution code:
# ABC 173 D

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

Submission status: Wrong Answer

Solution code:
def main():
    _ = input()
    A = sorted(list(map(int, input().split())))[::-1]
    print(sum(A[:-1]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

a.sort()
suma = sum(a)-a[0]

print(suma)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
ans = 0
for k in range(1, N):
  print(N-k//2)
  ans += A[N-k//2-1]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
many = int(input())
player = sorted(list(map(int, input().split())), reverse=True)
comfort_counter = 0
original = 2
spots = 0
current = 0
checker = False
for number in player:
    if current == 0:
        current = number
        checker = True
    elif checker == True:
        comfort_counter += current
        current = number
        spots = 2
        checker = False
    else:
        comfort_counter += current
        spots -= 1
        if spots == 0:
            spots == original * 2
            original = original * 2
            current = number
print(comfort_counter)

Submission status: Wrong Answer

Solution code:

N = int(input())
a = sorted(list(map(int, input().split())))



ans = 0
for i in range(N):
    ans += a[i]

ans -= a[0]

print(ans)

Submission status: Wrong Answer

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

sortA = sorted(A)
print(sum(sortA[1:]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from  collections import defaultdict
from collections import Counter
import bisect
def main():
    N = I()
    A = LI()
    A.sort(reverse=True)
    ans = A[0]
    cnt = 1
    i = 1
    while cnt < N - 1:
        ans += A[i] * 2
        cnt += 2
        i += 1
    if cnt > N - 1:
        ans -= A[i]
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from  collections import defaultdict
from collections import Counter
import bisect
def main():
    N = I()
    A = LI()
    A.sort(reverse=True)
    if N % 2 != 0:
        ans = sum(A[0:(N + 1) // 2]) * 2 - A[0] - A[(N + 1 // 2 - 1)]
    else:
        ans = sum(A[0:N // 2]) * 2 - A[0]

    print(ans)
if __name__ == "__main__":
    main()

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())
p_list = input().split()
p_list = sorted(p_list,reverse=True)
ans_list = []
ans = 0
for i in range(0,len(p_list)):
  if i!=0:
    ans_list.append(p_list[i])
    ans_list.append(p_list[i])
  else:
    ans_list.append(p_list[i])
for i in range(0,n-1):
	ans += int(ans_list[i])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
p_list = input().split()
p_list = sorted(p_list,reverse=True)
ans = 0
for i in range(0,len(p_list)-1):
  ans+=int(p_list[i])
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a_list = sorted(list(map(int, input().split())), reverse=True)
    ans = a_list[0]

    if (n - 2) % 2 == 0:
        for i in range((n - 2) // 2):
            ans += 2 * a_list[i + 1]
    else:
        for i in range((n - 2) // 2):
            ans += 2 * a_list[i + 1]
        ans += a_list[(n - 2) // 2]

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
INFINT = 1000000001
import math
n = int(input())
friendry = list(map(int,input().split()))
friendry.sort()
friendry.reverse()
min_score = friendry[0]
ans = 0
for i in range(1,n):
    ans += min_score
    min_score = min(friendry[i],min_score)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

A.sort(reverse=True)

comfortPoint = A[0]

for i in range(N)[1::]:
    comfortPoint += A[math.ceil(i/2)]

print(comfortPoint)

Submission status: Wrong Answer

Solution code:
import math , sys 
from collections import deque

N = int( input() )
Cs = list( map( int , input().split() ))
Cs.sort(reverse=True)
print(sum(Cs[:-1]))
"""
conf=0
d=deque()
i=0
while len(Cs)>0:
    tar=Cs.pop(0)
    #print(tar,Cs)
    if i==0:
        conf+=tar
        #d.append(tar)
        i+=1
    elif i==1:
        #conf+=d[0]
        #d.append(tar)
        Ds=deque([tar,tar])
        i+=1
    else:
        #print(Ds,d)
        c=max(Ds)
        conf+=c
        ind=Ds.index(c)
        #d.insert(ind,tar)
        Ds.insert(ind,tar)
        Ds[ind+1]=tar
        #print(Ds,d)
print(conf)
"""

Submission status: Wrong Answer

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

ans = A[0] + A[1]*(n-2)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
if n == 2:
  print(max(A))
else:
  A.sort(reverse=True)
  ans = A[0] + A[1]
  for a in A[2:n // 2 + 1]:
    ans += a
  print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = sum(A[:N//2])
ans += sum(A[1:round(N/2)])
print(ans)

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(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())

As = sorted(map(int, input().split()), reverse=True)

score = As[0]
counter = 0
index = 2

for i in range(2, N):
  score += As[index]
  if counter == 0:
    counter += 1
  else:
    counter -= 1
    index += 1
    
print(score)

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):
  ans += A[(i+1)//2]
  
print(ans)

Submission status: Wrong Answer

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

a.sort(reverse=True)
ans = a[-1]
for i in range(0, n-2):
    ans += a[i // 2]
    #print(ans)

print(ans)

Submission status: Wrong Answer

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

a.sort()
ans = a[-1]
ans += a[-2] * (n-2)

print(ans)

Submission status: Wrong Answer

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

a.sort()
del a[0]
ans = sum(a)

print(ans)

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:
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''


n=int(input())
a=list(map(int,input().split()))
a.sort()
#print(a)
ans=0
from math import floor
for i in range(1,n-1):
    ans+=a[n-1-floor(i/2)]
    #print(ans)
print(ans)

Submission status: Wrong Answer

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

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

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

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(len(A)-1):
    ans+=A[N-1-i//2]
print(ans)

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:
import heapq


def main():
    _ = int(input())
    A = sorted(list(map(int, input().split())), reverse=True)
    q = []
    heapq.heapify(q)
    ans = A[0]
    tmp_score = min(A[0], A[1])
    heapq.heappush(q, (-tmp_score, A[0], A[1]))

    for a in A[2:]:
        g = heapq.heappop(q)
        ans += -g[0]
        tmp_score1 = min(a, g[1])
        tmp_push1 = (-tmp_score1, a, g[1])

        tmp_score2 = min(a, g[2])
        tmp_push2 = (-tmp_score2, a, g[2])

        heapq.heappush(q, tmp_push1)
        heapq.heappush(q, tmp_push2)

    print(ans)


if __name__ == '__main__':
    main()

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+1):
  ans += a[n-i//2-1]
  
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

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

print(sum(a[:n//2+1])*2-a[0]*2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import heapq

n=int(input())
a=list(map(int,input().split()))
a=list(map(lambda x : x*(-1),a))

heapq.heapify(a)
total=0

for i in range(n-1) :
    total+=(-1)*heapq.heappop(a)

print(total)

Submission status: Wrong Answer

Solution code:
import math
from itertools import combinations
from itertools import combinations_with_replacement
from itertools import product
from collections import defaultdict
from collections import deque
from collections import Counter
import heapq


def input_li():
    return list(map(int, input().split()))


N = int(input())
A_LI = sorted(input_li())
print(sum(A_LI[1:]))

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]
lst.sort(reverse=True)
#print(lst)

num_list = []
count_list = []
for i in range(n):
  if i == 0:
    num_list.append(lst[i])
    count = 1
  else:
    if lst[i - 1] == lst[i]:
      count += 1
    else:
      count_list.append(count)
      num_list.append(lst[i])
      count = 1
    if i == n - 1:
      count_list.append(count)
#print(num_list)
#print(count_list)

m = len(num_list)
total = 0
count = 0
k = 0
for i in range(m):
  if i == 0:
    k += 2 * count_list[i] - 1
    if k <= n - 1:
      total += num_list[i] * (2 * count_list[i] - 1)
      count += count_list[i]
    else:
      total += num_list[i] * (n - 1)
      break
  else:
    if count_list[i] > count:
      k += count + count_list[i]
      if k < n - 1:
        total += num_list[i] * (count + count_list[i])
      else:
        k -= count + count_list[i]
        total += num_list[i] * (n - k - 1)
        break
    else:
      k += 2 * count_list[i]
      if k < n - 1:
        total += num_list[i] * 2 * count_list[i]
      else:
        k -= 2 * count_list[i]
        total += num_list[i] * (n - k - 1)
        break
    count += count_list[i]
print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]
lst.sort(reverse=True)
#print(lst)

num_list = []
count_list = []
for i in range(n):
  if i == 0:
    num_list.append(lst[i])
    count = 1
  else:
    if lst[i - 1] == lst[i]:
      count += 1
    else:
      count_list.append(count)
      num_list.append(lst[i])
      count = 1
    if i == n - 1:
      count_list.append(count)
#print(num_list)
#print(count_list)

m = len(num_list)
total = 0
count = 0
k = 0
for i in range(m):
  if i == 0:
    k += 2 * count_list[i] - 1
    if k <= n - 1:
      total += num_list[i] * (2 * count_list[i] - 1)
      count += count_list[i]
    else:
      total += num_list[i] * (n - 1)
      break
  else:
    if count_list[i] > count:
      k += count + count_list[i]
      if k <= n - 1:
        total += num_list[i] * (count + count_list[i])
      else:
        k -= count + count_list[i]
        total += num_list[i] * (n - k - 1)
        break
    else:
      k += 2 * count_list[i]
      if k <= n - 1:
        total += num_list[i] * 2 * count_list[i]
      else:
        k -= 2 * count_list[i]
        total += num_list[i] * (n - k - 1)
        break
    count += count_list[i]
print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]
lst.sort(reverse=True)
#print(lst)

num_list = []
count_list = []
for i in range(n):
  if i == 0:
    num_list.append(lst[i])
    count = 1
  else:
    if lst[i - 1] == lst[i]:
      count += 1
    else:
      count_list.append(count)
      num_list.append(lst[i])
      count = 1
    if i == n - 1:
      count_list.append(count)
#print(num_list)
#print(count_list)

m = len(num_list)
total = 0
count = 0
k = 0
for i in range(m):
  if i == 0:
    k += 2 * count_list[i] - 1
    if k <= n - 1:
      total += num_list[i] * (2 * count_list[i] - 1)
      count += count_list[i]
    else:
      total += num_list[i] * (n - 1)
      break
  else:
    if count_list[i] > count:
      k += count + count_list[i]
      if k <= n - 1:
        total += num_list[i] * (count + count_list[i])
      else:
        k -= count + count_list[i]
        total += num_list[i] * (n - k - 1)
        break
    else:
      k += 2 * count_list[i]
      if k <= n - 1:
        total += num_list[i] * 2 * count_list[i]
      else:
        k -= 2 * count_list[i]
        total += num_list[i] * (n - k - 1)
    count += count_list[i]
print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
if n % 2:
    print(a[0]+2*(sum(a[1:(n+1)//2])))
else:
    print(a[0]+2*(sum(a[1:n//2])))

Submission status: Wrong Answer

Solution code:
input();print(sum(A:=[*map(int,input().split())])-min(A))

Submission status: Wrong Answer

Solution code:
score = 0
turn = 0
n = int(input())
people = sorted(list(map(int, input().split())), reverse=True)

remain = n-1
while True:
    if remain >= 2**turn:
        score += people[turn] * (1+int(turn>0))
        remain -= 2 ** turn
        turn += 1
    else:
        score += people[turn] * remain
        break
    
print(score)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D_fix
# CreatedDate:  2020-07-06 21:04:46 +0900
# LastModified: 2020-08-30 09:12:58 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n = int(input())
    a = sorted(list(map(int, input().split())))
    confortable = sum(a[1:])
    print(confortable)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Ans = sum(an) - min(an)

print(Ans)

Submission status: Wrong Answer

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

b = [[0], [a[0]]]
ans = 0
for i in range(n):
    ans += min(b[0][-1], b[1][-1])
    b[i%2].append(a[i])
print(ans)

Submission status: Wrong Answer

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


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(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()
print(sum(L[1:]))

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:
import math
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

N = I()
A = LI()

A.sort(reverse=True)
# print(A)
# half = math.ceil(len(A)/2)
q, mod = divmod(len(A),2)

if mod == 0:
    ans = A[0]
    for i in range(1,q):
        ans += 2 * A[i]
else:
    ans = A[0]
    for i in range(1,q):
        ans += 2 * A[i]
    ans -= A[q]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys; input = sys.stdin.readline
# n, m , k = map(int, input().split())
# matrix = [list(input().strip()) for _ in range(n)]

n = int(input())
lis = sorted(map(int, input().split()), reverse=True)
ans = lis[0]
i = 1
c = 1
while c<n:
	if n-1-c >= 2: ans += lis[i]*2; c += 2; i+=1
	else: break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import queue

def main():
    n = int(input())
    A = list(map(int,input().split()))
    A = sorted(A,reverse=True)
    q = queue.PriorityQueue()
    q.put([A[0],A[0]])
    ans = 0
    for a in A[1:]:
        _min, _max = q.get()
        ans += _min
        q.put([a,_min])
        q.put([a,_max])
    print(ans)
    return 

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    A = list(map(int,input().split()))
    A = sorted(A,reverse=True)
    print(sum(A[:-1]))
    return 

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

N = I()
A = LI()
ans = 0

A.sort(reverse=True)
# print(A)
half = math.ceil(len(A)/2)
# print(half)
for i in range(half):
    ans += A[i]

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

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
first = True
for num in range(n):
    if first:
        conf = 0
        first=False
    else:
        conf = conf + min(a[0:num])
print(conf)

Submission status: Wrong Answer

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

ans = 0
if n == 2:
    ans += a_l[0]
else:
    l = a_l[1]
    r = a_l[2]
    ans += a_l[0] + l
    for i in range(3,n):
        if i%2 != 0:
            ans += l
            l = a_l[i]
        else:
            ans += r
            r = a_l[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
argList = list(map(int, input().split()))
argList.sort()
argList = argList[::-1]
a1 =  a2 = argList[0]

k = 0
for i in range(1,len(argList)):    
    if (a1  < a2 ):
        k += a1
        a2 = argList[i]
        
    else:
        k += a2
        a1 = argList[i]
print(k)

Submission status: Wrong Answer

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

ans = 0
c = a_l[0]
for i in range(1,n):
    ans += c
    c = a_l[i]
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt=0

cnt+=a[-1]
cnt+=a[-2]*(n-2)

print(cnt)

Submission status: Wrong Answer

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

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(sorted(map(int, input().split()))[::-1])
x = 0
if n % 2 == 0:
    for i in range(int(n / 2 - 1)):
        x += (a[i] + a[i + 1])
    x += a[int(n / 2)]
else:
    for j in range(int((n - 1) / 2)):
        x += (a[j] + a[j + 1])
print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(sorted(map(int, input().split()))[::-1])
del a[n - 1]
x = 0
for i in range(n - 1):
    x += a[i]
print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
cnt = n-2
ans = a[0]
for i in a[1:]:
  if cnt==0: break
  elif cnt>2:
    cnt -= 2
    ans += (i*2)
  else:
    cnt -=1
    ans += i
print(ans)

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())
a = list(map(int,input().split()))
b = sorted(a,reverse = True)
ans = 0
for i in range(0,n):
        if i == 0:
            ans += 0
        else:
            ans += b[n-(i//2)-1]
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
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(map(int, input().split()))

A.sort(reverse=True)

ans = sum(A[0:N-1])
print(ans)

Submission status: Wrong Answer

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

A = sorted(A,reverse=True)

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from itertools import chain
# form bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
# import numpy as np


def solve(N: int, A: "List[int]"):
    return sum(A) - min(A)


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N, A = map(int, line.split())
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    answer = solve(N, A)
    print(answer)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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:
input()
a = list(map(int, input().split()))
print(sum(a) - min(a))

Submission status: Wrong Answer

Solution code:
N = int(input())

array = list(map(int, input().split( )))
sarr = sorted(array, reverse = True)
ans = 0
for i in range(N-1):
#  print(sarr)
  ans += sarr[i]
print(ans)

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(1, n):
    ans += A[i-1]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]

print(sum(sorted(A)[1:N]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if N % 2 == 1:
  ans += A[0]
  ans += A[N//2 + 1]
  for i in range(1,N//2):
    ans += A[i]*2
else:
  ans += A[0]
  for i in range(1,N//2):
    ans += A[i]*2
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

def main():
    N = int( sys.stdin.readline() )
    A_list = list(map(int, sys.stdin.readline().split()))

    A_list.sort(reverse=True)
    arrived_idx = 1
    comfort = A_list[0]


    for i in range(2, len(A_list)):
        if ( len(A_list) - 1 - arrived_idx ) >= 2:
            comfort += (A_list[i] * 2)
            arrived_idx += 2
        elif ( len(A_list) - 1 - arrived_idx ) == 1:
            comfort += A_list[i]
            break
        else:  # ( len(A_list) - 1 - arrived_idx ) == 0:
            break


    print(comfort)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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