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
input = sys.stdin.readline
import heapq
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    ans = A[-1]
    m = min(A.pop(), A.pop())
    target = [-1*m]
    heapq.heapify(target)
    while len(A) > 0:
        a, b = 0, 0
        if len(target) >= 2:
            a, b = -1 * heapq.heappop(target), -1 * heapq.heappop(target)
        else:
            a = -1 * heapq.heappop(target)
        cur = max(a, b)
        ans += cur
        if len(target) < 2:
            heapq.heappush(target, -1 * a)
        else:
            heapq.heappush(target, -1 * cur)
        heapq.heappush(target, -1 * A.pop())
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import heapq


def get_tuple(a, b):
    if a > b:
        a, b = b, a
    return 2*b + a, a, b


def main(a, N):
    a.sort(reverse=True)
    h = []
    comfort = a[0]
    heapq.heappush(h, get_tuple(a[0], a[1]))
    for i in range(N - 2):
        val = heapq.heappop(h)
        comfort += val[1]
        heapq.heappush(h, get_tuple(a[i], val[1]))
        heapq.heappush(h, get_tuple(a[i], val[2]))
    print(comfort)


if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))
    main(a, N)

Submission status: Wrong Answer

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

r = a_sorted[0]
i = 2
while i > 1 and i < n:
    r = r + min(a_sorted[i-1], a_sorted[i-2])
    i += 1

print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 整数の入力
import numpy as np
N = int(input())
A_list = list(map(int, input().split()))
A = np.array(A_list)
ans = np.sum(A) - np.max(A)
print(ans)

Submission status: Wrong Answer

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

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

if N%2==1:
    ans-=A[int((N-1)/2)-1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(input().split())
l = [int(s) for s in l]
l.sort()
ans = sum(l)
ans = ans -l[0]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A.sort()
A.reverse()
ans = 0
c = []
count = 0
for i in range(N): 
  if count <= 1:
    c.append(A[i])
    ans+=A[i]
  else:
    c.sort()
    c.reverse()
    c.insert(1,A[i])
    #print(c)
    ans += min(c[0],c[2])
  count += 1

print(ans-A[1])

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int,input().split()))
A.sort(reverse=-1)
ans=A[0]
check =[A[0],A[1]]
for i in A[2:]:
    ans+=min(check)
    if(check[0]<i):
        check[0]=i
    elif(check[1]<i):
        check[1]=i
print(ans)

Submission status: Wrong Answer

Solution code:
import subprocess
import os
import time


import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    nums = [int(x) for x in input().split()]
    nums.sort(reverse=True)

    r = [nums.pop(0)]

    ans = 0
    while len(nums):
        n = nums.pop(0)
        i = r.index(max(r))
        ans += r[i]
        r = r[0:i] + [n] + [n] + r[i+1:-1]

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split())) 
b = sum(a) - min(a)
if b > 10*9 + 7:
  b = b % (10*9 + 7)
print(b)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

A.sort()
A.reverse()

ans = 0

count = 0
for i in range(len(A)):
  if i == 0:
    ans += A[i]
    count += 1
  else:
    ans += A[i]
    count += 1
    if count == len(A)-1:
      break
    count += 1
    ans += A[i]
    if count == len(A)-1:
      break

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.sort([int(x) for x in input().split()])[::-1]
Cnf = sum(A[:2])
Per = [0,1,2]
for T in range(3,N):
    Confort = np.hstack((min(A[Per[0]],A[Per[-1]]),np.array([min(A[Per[x]],A[Per[x+1]]) for x in range(0,T-1)])))
    Index = np.argmax(Confort)
    Cnf += np.max(Confort)
    Per.insert(Index,T)
print(Cnf)

Submission status: Wrong Answer

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

def li():
    return [int(x) for x in input().split()]

N = int(input())
A = li()

A.sort(reverse=True)

B = [A[i] for i in range(N) if i < N//2]

# 9 8 7 6 5
# 9 1 8 2 7 3 6 4 5
# 9 6 8 7
# 9+8+7+6+5+6+7+8

# 8 7 6 5
# 8 1 7 2 6 3 5 4
# 8+7+6+5+5+6+7

sm = B[0] + sum(B[i] * 2 for i in range(len(B)) if 0 < i)
print(sm)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int,input().split()))
A_list.sort(reverse = True)
indx_list = []
for i in range(1,100000,2):
    indx_list.append(i)
insx_list = []
for j in range(0,20):
    insx_list.extend(indx_list[:2 ** j])
mx_cmfrt = 0
reached_list = [A_list[0],A_list[0]]
for j in range(1, len(A_list)):
    cmfrt = min(reached_list[insx_list[j-1]-1],reached_list[insx_list[j-1]])
    reached_list.insert(insx_list[j-1], A_list[j])
    mx_cmfrt += cmfrt
print(mx_cmfrt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = solve(n, a)
    print(ans)

def solve(n, a):
    a.sort()
    ans = 0
    ans += sum(a[-(n // 2) - n % 2:])
    ans *= 2
    if n % 2:
        ans -= a[-(n // 2)]
    ans -= a[-1]
    return ans

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
a.sort()
c = int(a[-1])
if n%2 == 0:
  n1 = n//2-1
  for i in range(n1):
    a1 = int(a[n-2-i])
    c += a1*2
else:
  n2 = n//2
  a3 = int(a[n-n2-1])
  c += a3
  for i in range(n2):
    a2 = int(a[n-2-i])
    c += a2*2
print(c)

Submission status: Wrong Answer

Solution code:
# 整数の入力
import numpy as np
N = int(input())
A_list = list(map(int, input().split()))
A = np.array(A_list)
ans = np.sum(A) - np.min(A)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n, *a = map(int, read().split())

a = sorted(a, reverse=True)

b = [0]
b = b + a
b[-1] = 0

ans = sum(b)

print(ans)

Submission status: Wrong Answer

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



print(sum(a_list)-min(a_list))

Submission status: Wrong Answer

Solution code:
import sys

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

    A.sort(reverse=True)

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

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
med = a[n//2]
b = [a[i]-med for i in range(n)]
b.sort()
print(sum(b[1:])+med*(n-1))

Submission status: Wrong Answer

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

right = Alist[1]
left = Alist[0]
comfort = Alist[0]
for i in range(2,N):
  if (right < left):
    comfort += right
    right = Alist[i]
  else:
    comfort += left
    left = Alist[i]
    

print(comfort)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
count = int(input())
people=input().split(" ")
people1=[]

for i in range(count):
    people1.append(int(people[i]))

people1.sort(reverse=True)
#print(people1)

ans_list=[]
ans=0
k=1
for i in range(len(people1)):
    if i ==0:
        ans_list.append(people1[0])
    elif i == 1:
        ans_list.insert(0,people1[1])
        ans = ans + people1[1]
    elif i == 2:
        ans_list.append(people1[2])
        ans = ans + people1[0]
    else:
        if i > k:
            ans_list.insert(k, people1[i])
            ans = ans + min(ans_list[k-1],ans_list[k+1])
            k = k + 2
        elif i == k:
            ans_list.insert(k, people1[i])
            ans = ans + min(ans_list[k-1],ans_list[0])
            k = 1
    #print(ans_list)
    #print(ans)


    
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 i in range(2,N-1):
  ans += max(A[i],A[i-1])
print(ans%(10**9+7))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
a.sort()
c = int(a[-1])
if n%2 == 0:
  n1 = n//2-1
  for i in range(n1):
    a1 = int(a[n-2-i])
    c += a1*2
else:
  n2 = n//2
  a3 = int(a[n-n2-1])
  c += a3
  for i in range(n2-1):
    a2 = int(a[n-2-i])
    c += a2*2
print(c)

Submission status: Wrong Answer

Solution code:
from collections import deque

n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
d = deque()
ans = a[0]
d.append((a[1],a[0]))
for i in a[2:]:
    t1,t2 = d.popleft()
    ans+=min(t1,t2)
    d.append((i,t2))
    d.append((i,t1))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
numlist = sorted(deque(map(int,input().split())))
ans = 0
for i in range(n-1):
    ans += numlist.pop()
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

n=ii()
a=ll()
a.sort()
a=a[::-1]
i=0
rem=n-1
ans=0
while(rem>0):
    k=min(2,i+1)
    rem-=k
    ans+=k*a[i]
    i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = [int(s) for s in input() if s != " "]
arr = sorted(arr)[::-1]
p = [0] * n
p[1] = arr[0]
l, r = arr[0], arr[1]
for i in range(2, n):
    if (i % 2) == 0:
        l = arr[i]
    else:
        r = arr[i]
    p[i] = max(l, r)

print(sum(p))

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
A_list = sorted(A_list, reverse=True)
L = []
Ans = 0
for a in A_list:
    if len(L) == 0:
        index = 0
        L.insert(index, a)
    elif len(L) == 1:
        index = 1
        point = max(L)
        Ans += point
        L.insert(index, a)
    else:
        L_max = -1
        L_max_index = -1
        for i in range(len(L)-1):
            L_min = min([L[i],L[i+1]])
            if L_min > L_max:
                L_max = L_min
                L_max_index = i 
        Ans += L_max
        L.insert(L_max_index, a)
print(Ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import collections
col= collections.Counter(A)

setA = set(A)

ans = 0
for i in reversed(list(setA)):
    ans += col[i] * i * 2
    N -= col[i] * 2
    if N < 0:
        ans += N * i
        break
print(ans-max(A))

Submission status: Wrong Answer

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

cnt = 0

# print(a)
for i in range(1,n):
    cnt += max(a[i - 1], a[i])
    # print(cnt)
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    min_a = min(a)
    sum_a = sum(a)
    print(sum_a - min_a)
        
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a1 = sorted(a, reverse=True)
if n % 2 == 0:
    aa = a1.count(max(a1))
    aaa = a1[aa:n//2]
    print(sum(aaa)*2+max(a1)*aa)
else:
    bb = a1.count(max(a1))
    bbb = sum(a1[bb:n//2])
    ccc = sum(a1[n//2:n//2+1])
    print(bbb+ccc+max(a1)**bb)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

a.sort(reverse=True)

point = 0
num_list = [a[0]]
for i in range(1, n):
  point += min(num_list)
  num_list.append(a[i])
print(point)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
med = a[n//2]
b = [a[i]-med for i in range(n)]
b.sort()
print(sum(b[1:])+med*(n-1))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a = (sorted(a))
a.reverse()

ans = 0
b = [a.pop(0)]
for i in a:
    index = b.index(max(b))
    ans += min(b[index], b[index - 1])
    b.insert(index - 1, i)

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

N = int(input())

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

num = len(As)
As = As[:num-1]

print(sum(As))

Submission status: Wrong Answer

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

print(sum(a_list)-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
m = [input() for l in range(1)]

m = m[0].split()
for i in range(0,len(m)):
    m[i] = int(m[i])

p = sorted(m, reverse=True)

t = p[0]
r = len(p)%2
if r == 0:
    s = len(p)//2
if r == 1:
    s = len(p)//2 + 1
 
if n == 1:
    print(0)
if n == 2:
    print(p[0])
if n >= 3:
    if r == 0:
        for i in range(1,s):
            t = t + p[i] * 2
    if r == 1:
        for i in range(1,s):
            t = t + p[i] *2
        t = t - p[s]
print(t)

Submission status: Wrong Answer

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

L = []
#ソートして先頭からやる
A.sort(reverse=True)
pprev = A.pop(0)

ans = 0
prev = A.pop(0)
ans = ans + prev


for i in A:
    ans = max(pprev,prev) + ans

    pprev=prev
    prev=i

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in 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()
if N == 2:
    print(A[1])
    quit()
a = A.pop()
b = A.pop()
c = A.pop()
B = [c,b,a]
ans = b + a
i = 0
while A:
    a = A.pop()
    ans += b
    b = c
    c = a
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import heapq


def get_tuple(a, b):
    if a > b:
        a, b = b, a
    return a, 2*b + a


def main(a, N):
    a.sort(reverse=True)
    h = []
    comfort = a[0]
    heapq.heappush(h, get_tuple(a[0], a[1]))
    for i in range(N - 2):
        val = heapq.heappop(h)
        comfort += val[0]
        heapq.heappush(h, get_tuple(a[i], val[0]))
        heapq.heappush(h, get_tuple(a[i], val[1]))
    print(comfort)


if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))
    main(a, N)

Submission status: Wrong Answer

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

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

a.sort(reverse=True)

s = 0


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

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:
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)

B = list()
ans = 0
m = 0
n = 3
for i, a in enumerate(A[:3]):
    if i == 0:
        B.append(a)
    elif i == 1:
        ans += B[0]
        B.append(a)
    elif i == 2:
        ans += min(B[0], B[1])
        B.append(a)

j = 1
for i, a in enumerate(A[3:]):
    B.insert(j, a)
    ans += min(B[(j-1)%len(B)], B[(j+1)%len(B)])
    j += 2

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()))
A.sort(reverse=True)

del A[-1]

print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A = sorted(A, reverse=True)
sum = A[0]
temp=[]
temp.append(A[0])
temp.append(A[1])
for i in range(2,len(A)):
  temp.append(A[i])
  sum += temp[len(temp)-2]
print(sum)

Submission status: Wrong Answer

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

list2=[]

c=0
a1 = 0
a2 = 0

for i in range(n):
    if i ==0:
        a1 = alist[i]
        c+=0
#        print("[{}]:{} gets 0".format(i,alist[i]))
    elif i==1:
        a2 = alist[i]
        c+=alist[0]
#        print("[{}]:{} gets {}".format(i,alist[i],a1))
    else:
        if a1 > a2:
            # a1の方が好感度高ければ、そちらにつけて、心地よさはa2を足す
#            print("[{}]:{} gets {} ({}/{})".format(i,alist[i],a2,a1,a2))
            c+=a2
            a2 = alist[i]
        else:
            # a2の方が好感度高ければ、そちらにつけて、心地よさはa1を足す
#            print("[{}]:{} gets {} ({}/{})".format(i,alist[i],a1,a1,a2))
            c+=a1
            a1 = alist[i]
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
l_sort = sorted(l,reverse=True)
l_len = len(l)
if(l_len%2==0):
    ans = sum(l_sort[:(l_len//2)-1]+l_sort[1:(l_len//2)+1])
else:
    ans = sum(l_sort[:(l_len//2)]+l_sort[1:(l_len//2)+1])

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import heapq
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    ans = A[-1]
    m = min(A.pop(), A.pop())
    target = [-1*m]
    heapq.heapify(target)
    while len(A) > 0:
        a, b = 0, 0
        if len(target) >= 2:
            a, b = -1 * heapq.heappop(target), -1 * heapq.heappop(target)
        else:
            a = -1 * heapq.heappop(target)
        cur = max(a, b)
        ans += cur
        if len(target) < 2:
            heapq.heappush(target, -1 * a)
        else:
            heapq.heappush(target, -1 * min(a, b))
        heapq.heappush(target, -1 * A.pop())
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int,input().split()))
c = []

ans = 0    

b = sorted(b, reverse=True)
c.append(b.pop(0))
ans += c[0]
c.append(b.pop(0))
nmax = 0
maxindex = 0
if a > 2:
    ans += c[1]
    c.append(b.pop(0))
    if a > 3:
        for i in range(a - 3):
            nmax = 0
            maxindex = 0
            for j in range(len(c)):
                if j + 1 == len(c):
                    nmax = min(c[j], c[0])
                    maxindex = j + 1
                else:
                    s = min(c[j], c[j + 1])
                    if nmax < s:
                        nmax = s
                        maxindex = j + 1
            ans += nmax
            c.insert(maxindex, b.pop(0))
print(str(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

play.sort(reverse=True)

print(sum(play)-min(play))

Submission status: Wrong Answer

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

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


n = I()
a = list(MI())

a.sort()
a.reverse()

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
if N == 2:
    print(A[1])
    quit()
a = A.pop()
b = A.pop()
c = A.pop()
B = [c,b,a]
ans = b + c
i = 0
while A:
    a = A.pop()
    ans += b
    b = c
    c = a
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
numlist = list(map(int, input().split()))
numlist.sort(reverse=True)
maxnum = max(numlist)
kazu = 0

for i in numlist:
    if maxnum == i:
        kazu += 1
    else:
        break

if len(numlist) <= kazu*2:
    print(maxnum*(len(numlist)-1))
else:
    hokanokazu = len(numlist)-kazu*2
    ans = maxnum*(kazu*2-1)
    if hokanokazu == 1:
        ans += numlist[kazu]
        print(ans)
    else:
        ans += sum(numlist[kazu:kazu+hokanokazu])
        print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
import sys

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

a.sort()
last_minus = a[0] 
a.sort(reverse = True)
c = collections.Counter(a)
ans = 0
cnt = 0

for i in c.keys():
    for j in c.values():
        if len(a) - 1 <= cnt + (2 * c[j] - 1):
            ans += c[i] * (len(a) - cnt - 1)
            print(abs(ans) - last_minus)
            sys.exit()
        else:
            ans += c[i] * (2 * c[j] - 1) 
            cnt += 2 * c[j] - 1

        
print(abs(ans) - last_minus)

Submission status: Wrong Answer

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

pos = [a[0], a[0]]
diff = [a[0]]
kokoti = 0
idx = 0
for i in range(1, n):
    kokoti += diff[idx]
    diff = diff[:idx] + [a[i], a[i]] + diff[idx+1:]
    pos = pos[:i] + [a[i]] + pos[i:]
    if idx == 0:
        idx = len(diff)-1
# print(diff)
print(kokoti)
# print(pos)

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int,input().split()))
A.sort(reverse=-1)
ans=A[0]
check =[A[0],A[1]]
for i in A[2:]:
    ans+=min(check)
    if(check[0]>i):
        check[0]=i
    elif(check[1]>i):
        check[1]=i
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
b=[]
b.append(a[0])
b.append(a[1])
ans=a[0]
for i in range(2,n):
    max_p=min(b[0],b[1])
    max_j=1
    for j in range(1,i-1):
        if min(b[i-2],b[i-1])>max_p:
            max_p=min(b[i-2],b[i-1])>max_p
            max_j=i-1
    b.insert(max_j,a[i])
    ans+=max_p
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if N%2==1:
    ans-=A[int((N-1)/2)-1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))  # 入力のときに N を使う必要はありません

print(sum(a)-min(a))

Submission status: Wrong Answer

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc173/abc173_d
import sys
from collections import deque

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    A = sorted(i2nn(), reverse=True)
    print(sum(A[:-1]))
    return

main()

Submission status: Wrong Answer

Solution code:
import sys

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

    A.sort(reverse=True)

    res=0
    res+=A[0]
    res+=A[1]*(N-2)
    print(res)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

A.sort()
A.reverse()

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int (x) for x in input().split()]
comfort = 0
B = 0
#数字がでかい順に到着させる
B = sorted(A)
comfort = sum(B)
comfort = comfort - B[0]
print(comfort)

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 i in range(2,N-1):
  ans += max(A[i],A[i-1])
print(max(ans,sum(A[:-1])))

Submission status: Wrong Answer

Solution code:
import io,sys,copy
sys.setrecursionlimit(10**6)


def main():
    n = int(input())
    A = list(map(int,sys.stdin.readline().rstrip().split()))

    A.sort(reverse=True)
    print(sum(A[:-1]))
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

scores = [0, a[0]]
for i in range(1,len(a)-1):
    score = a[0] if a[0]<=a[i] else a[i]
    scores.append(score)
print(sum(scores))

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=int(input())
ls=[int(s) for s in input().split()]
ls=sorted(ls,reverse=True)
ans=ls[0]
if N>=3:
  ans+=ls[1]
for i in range(3,N):
  ans+=ls[i-2]
print(ans)

Submission status: Wrong Answer

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

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def main():
    INF = 999999999999999999999999
    MOD = 10**9+7

    n,*A = get_all_int()
    A = list(A)
    A.sort(reverse=True)

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


main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
kokoti=0
A.sort(reverse=True)
#print(A)
for i in range(1,N-1):
    if(i==1):
        kokoti+=A[0]
        #print(kokoti,A[0],1)
    elif(i==N-1):
        kokoti+=A[i-1]
        #print(kokoti,A[i-1],2)
    if(A[i-1]<=A[N-i-2]):
        kokoti+=A[i-1]
        #print(kokoti,A[i-1],3)
    elif(A[i-1]>A[N-i-2]):
        kokoti+=A[N-i-2]
        #print(kokoti,A[N-i-2],4)
print(kokoti)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

confort = 0

edge = []

for i in range(n):
    if i == 0:
        continue
    elif i == 1:
        confort += friendly[0]
        edge.append(friendly[1])
        edge.append(friendly[1])
    else:
        max_edge = friendly[i-1]
        confort += max_edge
        edge.insert(edge.index(max_edge), friendly[i])
        edge.insert(edge.index(max_edge) + 1, friendly[i])
        
print(confort)

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

Submission status: Wrong Answer

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc173/abc173_d
import sys
from collections import deque

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    A = sorted(i2nn(), reverse=True)
    print(sum(A[:-1]))
    return

Submission status: Wrong Answer

Solution code:
import itertools
import decimal
import math
import collections
import sys
input = sys.stdin.readline
import copy

# S=(input())
# N=int(input())
# N,K=map(int,input().split())
# ListA=list(map(int,input().split()))
# ListA.sort()#reverse=True)



def resolve():
    N=int(input())
    ListA=list(map(int,input().split()))
    ListA.sort(reverse=True)

    tmp=[0]

    ans=0

    tmp[0]=ListA[0]
    flag=True
    for i in range(1,N):
        if(flag):
            flag=False
            tmp.insert(0,ListA[i])
            ans+=min(tmp[1],tmp[len(tmp)-1])

        else:
            flag=True
            tmp.insert(len(tmp),ListA[i])
            ans+=min(tmp[0],tmp[len(tmp)-2])


    print(ans) 



resolve()