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 heapq
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)

pq = []
res = 0
heapq.heapify(pq)

for i in range(n):
  if len(pq) < 1:
    heapq.heappush(pq, a[i])
    continue

  res += pq[0]
  heapq.heappush(pq, a[i])

print(res)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
Nlist = list(map(int, input().split()))
Nlist.sort(reverse=True)
x = math.ceil(N/2)
ans = sum(Nlist[0:x])*2-Nlist[0]
print(ans)
if N % 2 != 0:
    ans -= Nlist[x-1]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import queue

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	al.sort(reverse = True)
	q = queue.PriorityQueue()
	q.put((al[1], al[0]))
	q.put((al[1], al[0]))
	score = al[0]
	for v in al[2:]:
		f, t = q.get()
		score += f
		q.put((v, f))
		q.put((v, t))
	return score
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

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

a.sort()

suma = []
#1つめ
v = a.pop()
suma.append(0)
#2つめ
suma.append(v)
v2 = a.pop()
v = min(v,v2)
while a:
    suma.append(v)
    v2 = a.pop()
    v = min(v,v2) 

print(sum(suma))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
Nlist = list(map(int, input().split()))
Nlist.sort(reverse=True)
x = math.ceil(N/2)
ans = sum(Nlist[0:x])*2-Nlist[0]
if N % 2 != 0:
    ans -= Nlist[x]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in 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()));
a.sort(reverse=True)
com = 0;
for i in range(n-1):
    com += a[i]
print(com);

Submission status: Wrong Answer

Solution code:
N = int( input() ) 
A = sorted( list( map( int, input().split() ) ) )
 
total = 0
L = [A[N-1]]
cnt = 1
cnt1 = 1
for i in range( N - 2, -1, -1 ):
  a = L[0]
  total += a
  L.append( A[ i ] )
  L.append( A[ i ] )
  cnt += 2
  cnt1 += 1
  if cnt > N:
    break
 
print( total + sum(L[ :N-cnt1 ]) )

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import deque


def main():
    input()  # n
    friendliness = [int(x) for x in input().split()]
    friendliness.sort()
    edges = deque()
    edges.append(friendliness[-1])
    ans = 0
    for fri in friendliness[1:][::-1]:
        print(fri)
        edges.append(fri)
        edges.append(fri)
        ans += edges.popleft()
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque


def main():
    input()  # n
    friendliness = [int(x) for x in input().split()]
    friendliness.sort()
    edges = deque()
    ans = 0
    for fri in friendliness:
        edges.append(fri)
        edges.append(fri)
        ans += edges.popleft()
    ans -= friendliness[0]
    ans += edges.popleft()
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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

  max_ = A[0]
  max_iter = N-2
  iter_ = 0
  for i in range(1, N):
    for _ in range(2):
      max_ += A[i]
      iter_ += 1
      if iter_ >= max_iter:
        print(max_)
        return


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

Submission status: Wrong Answer

Solution code:
import heapq

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

ans = 0
ans += a[0]

h = []
heapq.heapify(h)
heapq.heappush(h, a[1])
heapq.heappush(h, a[1])

for i in range(2, n):
    b = heapq.heappop(h)
    ans += b
    heapq.heappush(h, a[i])
    heapq.heappush(h, a[i])

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    a = list(IL())
    da = sorted(a,reverse=True)
    if n<=5:
        ans = sum(da[:-1])
        print(ans)
        return
    ans = sum(da[:5])
    idx = 5
    for i in range(5,n):
        if i<8:
            ans += da[i-4]
        else:
            if i%2:
                idx += 1
            ans += da[i-idx]
    print(ans)
    return

if __name__=='__main__':
    Main()

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    a = list(IL())
    da = sorted(a,reverse=True)
    if n<=5:
        ans = sum(da[:-1])
        print(ans)
        return
    ans = sum(da[:4])
    idx = 5
    for i in range(5,n):
        if i<8:
            ans += da[i-4]
        else:
            if i%2:
                idx += 1
            ans += da[i-idx]
    print(ans)
    return

if __name__=='__main__':
    Main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

l = int(input())

a = map(int, input().split())
a = sorted(a, reverse=True)
print(a)
if l%2==0:
	print(a[0] + sum(a[1:(l-2)//2])*2 + a[(l-2)//2])
else:
	print(a[0] + sum(a[1:(l+1)//2])*2)

Submission status: Wrong Answer

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

ans = 0
if n >= len(A):
  ans = sum(A)-1
  
else:
  ans += A[1]
  t = n-1
  for i in range(1, n):
    lim = 2
    for j in range(0, lim):
      if t > 0: ans += A[i]
      t -= 1
      
print(ans)

Submission status: Wrong Answer

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

x=A.pop(0)
cnt=0
conf=0
y=0
for i in A:
  if cnt==0:
    y=i    
  cnt+=1
  if cnt%2==0:
    conf+=p
    x=y
  else:
    p=x+y
    y=i


if cnt%2==1:
  conf+=x
print(conf)

Submission status: Wrong Answer

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

ans = 0
if n >= len(A):
  ans = sum(A)-1
  
else:
  ans = sum(A[1:n//2+1])
  print(ans)
  ans *= 2
  ans += A[0]
            
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
A = inl()


def solve():
    A.sort(reverse=True)
    return sum(A[:-1])


print(solve())

Submission status: Wrong Answer

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

ans = 0
if n >= len(A):
  ans = sum(A)-1
  
else:
  ans = sum(A[1:n//2+1])
  print(ans)
  ans *= 2
  print(ans)
  ans += A[0]
            
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

dic = {}
lis = []
for i in a:
    if i in dic:
        dic[i] = dic[i] + 1
    else:
        dic[i] = 1
        lis.append(i)

lis.sort()
lis.reverse()

ans = 0
n -= 1
for i in lis:
    k = 2 * dic[i] - 1
    if n - k >= 0:
        ans += i * k
    else:
        ans += i * n
        #print("owari")
        break
    #print(ans)
    #print(n,dic[i])
    n -= k

#print(dic,lis)
print(ans)

Submission status: Wrong Answer

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

ans = 0
if n >= len(A):
  ans = sum(A)-1
  
else:
  ans = sum(A[1:(n-1)//2+1])
  ans *= 2
  ans += A[0]
            
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

s = sum(a) - min(a)

print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().strip().split()))
a.sort(reverse=True)
na=[]
cost=0
na.append(a[0])
na.append(a[1])
cost+=a[0]
for i in range(2,n):
    #print(a[i])
    cost+=a[n-1-i//2]
    #print(na)
print(cost)

Submission status: Wrong Answer

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

asum=[0]

for i in range(n-1):
  asum.append(asum[i]+a[i])
  
print(asum[n-1])

Submission status: Wrong Answer

Solution code:
# D - Chat in a Circle
def main():
    N, *A = map(int, open(0).read().split())
    A.sort()
    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()
A.reverse()
half1 = [A[0]]
half2 = [A[0]]
comfortable = 0
for i in range(1, len(A)):
  comfortable += min(half1[-1], half2[-1])
  if i % 2:
    half1.append(A[i])
  else:
    half2.append(A[i])
print(comfortable)

Submission status: Wrong Answer

Solution code:

N = input()

a = map(int, input().split())
a = sorted(a, reverse=True)
l = len(a)
if l%2==0:
	print(a[0] + sum(a[1:l//2])*2 + a[1//2])
else:
	print(a[0] + sum(a[1:(l+1)//2])*2)

Submission status: Wrong Answer

Solution code:

def resolve():
    N = int(input())
    A = sorted(map(int, input().split()), reverse=True)
    ans = sum(A[:-1])
    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]

#-------------------------code---------------------------#
#vsInput()

n=Int()
a=array()
a.sort(reverse=True)
ans=sum(a[0:-1])
print(ans)

Submission status: Wrong Answer

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

A.sort(reverse=True)

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

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 = list(map(int,input().split()))
a.sort(reverse=True)
a = a[:-1]
print(sum(a))

Submission status: Wrong Answer

Solution code:
#ord(s)
import copy
from collections import deque

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
d = deque()
c = 0
count = 2
ans = 0

if N == 2:
    print(A[0])
elif N == 3:
    print(A[0] + A[1])
else:
    ans = A[0] + A[1]
    for i in range(3, N-1):
        if c == 0:
            ans += A[count]
        elif c == 1:
            ans += A[count]
            count += 1
            c = 0
    ans += A[1]
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(N-1):
    ans += A[i+1//2]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int,input().split()))
 
lst.sort(reverse=True)
sum = lst[0]
i = 1
Flag = True
while(i <  n-1):
  if Flag:
    sum += lst[i]
    Flag = False
  else:
    sum += lst[i-1]
    Flag = True
  i += 1
 
print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int,input().split()))
 
lst.sort(reverse=True)
sum = lst[0]
Flag = True
for i in range(n-1):
  if Flag:
    sum += lst[i]
    Flag = False
  else:
    sum += lst[i-1]
    Flag = True

print(sum)

Submission status: Wrong Answer

Solution code:
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

Submission status: Wrong Answer

Solution code:

N = input()


a = map(int, input().split())
a = sorted(a, reverse=True)
print(a[0] + sum(a[1:len(a)//2])*2)

Submission status: Wrong Answer

Solution code:
import heapq

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

hp=[]

ans=-A[0]
heapq.heappush(hp,0)

for a in A:
    ans+=heapq.heappop(hp)
    heapq.heappush(hp,-a)
    heapq.heappush(hp,-a)
print(-ans)

Submission status: Wrong Answer

Solution code:
import heapq

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

hp=[]

ans=-A[0]
heapq.heappush(hp,-A[0])
heapq.heappush(hp,-A[1])

for a in A[2:]:
    ans+=heapq.heappop(hp)
    heapq.heappush(hp,-a)
    heapq.heappush(hp,-a)
print(-ans)

Submission status: Wrong Answer

Solution code:
import heapq

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

hp=[]

ans=-A[1]
heapq.heappush(hp,-A[0])
heapq.heappush(hp,-A[1])

for a in A[2:]:
    ans+=heapq.heappop(hp)
    heapq.heappush(hp,-a)
    heapq.heappush(hp,-a)
print(-ans)

Submission status: Wrong Answer

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

if N == 1:
    print(0)
else:
    print(sum(A[1:]))

Submission status: Wrong Answer

Solution code:

N = input()


a = map(int, input().split())
a = sorted(a, reverse=True)
result = 0
pre = a[0]
for i in a[1:]:
	result += min(a[0], pre)
	pre = i
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = sorted([int(x) for x in input().split(" ")], reverse=True)
S = arr[0]
iter = 1
c = False
for i in range(n - 2):
    if c:
        S += arr[iter]
        c = True
    else:
        S += arr[iter]
        c = False
        iter += 1
        
print(S)

Submission status: Wrong Answer

Solution code:

N = input()


a = list(map(int, input().split()))
#print(a)
print(sum(a)-min(a))

Submission status: Wrong Answer

Solution code:
#from collections import Counter

def main():
    N = int(input())
    A = [int(c) for c in input().split()]
    A.sort()
    #print(A)

    B = [A.pop()]
    score = B[0]
    B.append(A.pop())
    while len(A) > 0:
        a = A.pop()
        c = -1
        idx = 0
        for i in range(len(B)):
            if i==len(B)-1:
                t = min(B[i], B[0])
            else:
                t = min(B[i], B[i+1])
            if t > c:
                c = t
                idx = i
        score += c
        B.insert(idx, a)
    #print(B)
    print(score)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

sorted=sorted(a,reverse=True)
#print(len(sorted[2:])//2)
ans=sorted[0]

for i in range(1,len(sorted[2:])//2 + 1):
  ans+=sorted[1+i]*2
  #print(sorted[1+i])
  

if len(a)%2==1:
  ans+=sorted[2 + len(sorted[2:])//2]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import OrderedDict, defaultdict
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
#import numba

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

    val_list = []
    heappush(val_list, (-min(A[0], A[1]), A[1], A[0], 1))
    ans = A[0]

    for a in A[2:]:
        val, a1, a2, edge = heappop(val_list)
        ans += -val
        if edge != 1:
            heappush(val_list, (-a, a, a1, 0))
            heappush(val_list, (-a, a, a2, 0))
        else:
            heappush(val_list, (-a, a, a1, 1))
            heappush(val_list, (-a, a, a2, 0))
    print(ans)



if __name__ == "__main__":
    run()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    a = LI()
    a.sort()
    ans = 0
    a = a[::-1]
    for i in range(n):
        ans += a[(i + 1) // 2]
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

A.sort(reverse=True)

# 初期状態 
ans = 0
count = 0

# 一人目
count = 1

# 二人目
ans = A[0]
count = 2

#３人目以降
for i in range(1,N):
  ans += A[i]
  count += 1
  if count == N:
    break
  ans += A[i]
  count += 1
  if count == N:
    break
print(ans)

Submission status: Wrong Answer

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

def quickSort(arr):

    # 配列のメジアンより小さい要素を集めた配列
    left = []

    # 配列のメジアンより大きい要素を集めた配列
    right = []

    # 再帰の停止条件
    # 再帰的に配列を分割した後の、要素数が1以下になったら停止する
    if len(arr) <= 1:
        return arr

    # 配列の中央値(メジアン)を取得する
    median = int(statistics.median(arr))

    # 配列内に含まれる中央値の個数を数えるための変数
    medianFlg = 0

    for element in arr:
        # 配列の要素(element)が中央値より小さいので、
        # 配列leftに値を格納する
        if element < median:
            right.append(element)
        # 配列の要素(element)が中央値より大きいので、
        # 配列rightに値を格納する
        elif element > median:
            left.append(element)
        else:
        # elementが配列の中央値の場合は、
        # 返り値に加える中央値の個数分だけ、フラグに+1し続ける
            medianFlg += 1

    # 配列left、配列right毎に再帰を行い
    # 配列を小さな配列に区切る
    left = quickSort(left)
    right = quickSort(right)

    # 配列left、中央値の[median]、配列rightを結合したものを返す
    return left + [median] * medianFlg + right

A=quickSort(A)
count=2
ans=A[0]
A.pop(0)
while count<N:
    add_num=A.pop(0)
    ans+=add_num*2
    count+=2
    if count>N:
        ans-add_num

print("{}".format(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans=0
now=0
num=0
Anum=[A[0]]
kaisuu=[1]

for i in range(1,N):
  if A[i]==Anum[now]:
    kaisuu[now]+=1
    ans+=Anum[now]
  else:
    if A[i]!=Anum[-1]:
      num+=1
      Anum.append(A[i])
      kaisuu.append(1)
    else:
      kaisuu[num]+=1
    if kaisuu[now]>0:
      kaisuu[now]-=1
      ans+=Anum[now]
    else:
      now+=1
      ans+=Anum[now]

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import random # ランダムな配列の生成用
N=int(input())
A = list(map(int, input().strip().split()))

import os
import statistics

def quickSort(arr):

    # 配列のメジアンより小さい要素を集めた配列
    left = []

    # 配列のメジアンより大きい要素を集めた配列
    right = []

    # 再帰の停止条件
    # 再帰的に配列を分割した後の、要素数が1以下になったら停止する
    if len(arr) <= 1:
        return arr

    # 配列の中央値(メジアン)を取得する
    median = int(statistics.median(arr))

    # 配列内に含まれる中央値の個数を数えるための変数
    medianFlg = 0

    for element in arr:
        # 配列の要素(element)が中央値より小さいので、
        # 配列leftに値を格納する
        if element < median:
            left.append(element)
        # 配列の要素(element)が中央値より大きいので、
        # 配列rightに値を格納する
        elif element > median:
            right.append(element)
        else:
        # elementが配列の中央値の場合は、
        # 返り値に加える中央値の個数分だけ、フラグに+1し続ける
            medianFlg += 1

    # 配列がどのように分割されているかを確かめたい場合は、
    # このタイミングでprintで確認すると良い
    # print(left)
    # print(right)

    # 配列left、配列right毎に再帰を行い
    # 配列を小さな配列に区切る
    left = quickSort(left)
    right = quickSort(right)

    # 配列left、中央値の[median]、配列rightを結合したものを返す
    return left + [median] * medianFlg + right

A=quickSort(A)
A.reverse()
count=2
ans=A[0]
A.pop(0)
while count<N:
    add_num=A.pop(0)
    print(add_num)
    ans+=add_num*2
    count+=2
    if count>N:
        ans-add_num





print("{}".format(ans))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

c.sort(reverse=True)
ans = 0

for i in range(1,len(c)):
  ans += c[len(c) - 1 - i//2]

print(ans)

Submission status: Wrong Answer

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

c.sort(reverse=True)
ans = c[0]

for i in range(1,n-1):
    #print(int(i/2+1))
    ans = ans + c[int(i/2+1)]

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re


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


if N == 2:
    print(A[0])
    exit()
elif N == 3:
    print(A[0]+A[1])

chk = []
chk.append(0)
chk.append(1)

for i in range(N-3):
    chk.append((i//2)+2)

ans = 0

for i in range(N-1):
    ans += A[int(chk[i])]

print(ans)

Submission status: Wrong Answer

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

A = sorted(A)
ans =0
if N >= 3:
  for i in range(1,len(A)):
    ans += A[len(A) - 1 - i//2]
           
print(ans)

Submission status: Wrong Answer

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

pops    = 1
mins    = [ ai[0] ]
comfort = 0

while pops < len(ai):
    comfort += sum(mins[: len(ai) - pops ])
    mins = [ *mins[ pops : pops + len(mins) ], ai[pops] ]
    pops += len(mins)

print(comfort)

Submission status: Wrong Answer

Solution code:
N = int(input())
num = list(map(int,input().split()))
num.sort(reverse = True)
count = num[0]
num.pop(0)
switch = 0
cc = 0
for i in range(N-1):
  count += 2*num[i]
  cc += 2
  if(cc == (N-1)-2 ):
    count += num[i+1]
    cc += 1
  if(cc == (N-1)-1 ):
    print(count)
    exit()

Submission status: Wrong Answer

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

conf = sum(man[0:N-1])

print(conf)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A = sorted(A, reverse=True)
ans = A[0]
if N >= 3:
  if(N%2==0):
    ans += sum(A[1:int(len(A)/2)])*2
  else:
    ans += sum(A[1:int(len(A)/2)])*2 + A[int(len(A)/2)+1]
           
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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

# print('N,A:',N,A)

#out=A[-1]
out=0

flag=0
cnt=0
i=0
while cnt<N-1:
    if flag==0:
        flag=1
    elif flag==1:
        i+=1
    out+=A[-1*(i+1)]
    # print('A[-1*(i+1)],out:', A[-1*(i+1)],out)
    cnt+=1

print(out)

Submission status: Wrong Answer

Solution code:
import collections

def resolve():
  N = int(input())
  A = [int(x) for x in input().split(" ")]
  setA = set(A)
  listA = list(setA)
  collectionA = collections.Counter(A)

  result = listA[-1]
  collectionA[listA[-1]] -= 1

  if collectionA[listA[-1]] == 0:
    listA.pop()

  for list_a in listA:
    collectionA[list_a] *= 2

  for i in range(N - 2):
    result += listA[-1]
    collectionA[listA[-1]] -= 1
    if collectionA[listA[-1]] == 0:
      listA.pop()

  print(result)


if __name__ == "__main__":
  resolve()

Submission status: Wrong Answer

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

A.sort(reverse=True)
ans = 0
tmp = 0
for i in range(N):
    if i == 0:
        continue
    elif i == 1:
        ans += A[0]
    elif i % 2 == 0:
        tmp = A[i-1]
        ans += tmp
    else:
        ans += tmp
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

A_sort = sorted(list(map(int, input().split())))

print(sum(A_sort[1:]))

Submission status: Wrong Answer

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

a.sort(reverse=True)

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

print(sum_comfort)

Submission status: Wrong Answer

Solution code:
n = int(input())
p_list = list(map(int, input().split(" ")))
p_list.sort(reverse = True)
a_list=[]
a=0
for i in range(n-1):
  if i == 0:
    a=p_list[i]
    a_list.append(p_list[i])
  elif i == 1:
    a += p_list[i]
    a_list.append(p_list[i])
  else:
    for x in range(i-1):
      x_list =[]
      if a_list[x-1] <= a_list[x+1]:
        x_list.append(a_list[x-1])
      else:
        x_list.append(a_list[x+1])
    a += max(x_list)
    a_list.insert(x_list.index(max(x_list)),p_list[i])
print(a)

Submission status: Wrong Answer

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