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:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *

input = sys.stdin.readline

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

inf = float('inf')
mod = 1000000007

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

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

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

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

	print(ans)




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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

if n==1: print(0)
else: print(sum(arr)-min(arr))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

L = sorted(L,reverse=True)
#print(L)

cnf = 0
for i in range(1,n):
    cnf += L[i-1]
    #print(i,cnf)

print(cnf)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int, input().split()))
sett = set(lst)
min_num = min(lst)

res = 0
while lst != []:
    max_num = max(lst)
    max_num_count = lst.count(max_num)
    res += max_num * (max_num_count - 1)
    res += max_num
    sett.remove(max_num)
    lst = list(filter(lambda x: x != max_num, lst))

res -= min_num
print(res)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = sorted(readInts(),reverse=True)
ans = 0
for i in range(n):
    if i == 0:
        prv = A[i]
    else:
        ans += prv
        prv = A[i]
print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    A.sort(reverse=True)
    ans = 0
    conut = 1
    for i in range(N):
        if i==0:
            ans += A[i]
            conut += 1
        else:
            ans += A[i]
            conut += 1
            if conut == N:
                break
            ans += A[i]
            conut += 1
            if conut==N:
                break
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N = k()
A = l()
A.sort()
A.reverse()
b = list(itertools.accumulate(A))

print(b[N-2])

Submission status: Wrong Answer

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

list.sort(inList, reverse=True)
print(sum(inList) - inList[-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
a.sort()
print(sum(a)-a[0])

Submission status: Wrong Answer

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

a.sort(reverse = True)

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

print(ans)

Submission status: Wrong Answer

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

for i in range(1,n):
    s += p
    if a[i] < p:
        p = a[i]
    
print(s)

Submission status: Wrong Answer

Solution code:
import heapq as hq
def resolve():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort(reverse= True)
    if N == 2:
        print(A[0])
        return
    if N == 3:
        print(A[0]+A[1])

    score = A[0]+A[1]
    lst = []
    hq.heappush(lst,A[1])
    hq.heappush(lst,A[2])
    hq.heappush(lst,A[2])
    for i in A[3:]:
        mn = hq.heappop(lst)
        score+= mn
        hq.heappush(lst,i)
    print(score)
resolve()

Submission status: Wrong Answer

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

A.sort(reverse=True)
ans = 0
cnt = 0
idx = 0
judge = True
while cnt < N-1:
    if idx % 2 == 0:
        ans += A[idx]
        cnt += 1
    else:
        ans += A[idx] + A[idx]
        cnt += 2
    idx += 1
if cnt == N:
    ans -= A[idx-1]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans=sum(b)-b[0]
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
from collections import deque

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

ans = 0
q = []
heapq.heapify(q)
while a:
    top = a.popleft()
    if len(q) > 1:
        first = heapq.heappop(q)
        second = heapq.heappop(q)
        ans += second * -1
        heapq.heappush(q, first)
        heapq.heappush(q, second)
    elif len(q) == 1:
        first = heapq.heappop(q)
        ans += first * -1
        heapq.heappush(q, first)

    heapq.heappush(q, -1 * top)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

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

t.sort(reverse=True)

ans = t[0]

i = 1

if n%2==0:
    while i < n-2:
        ans += t[i]*2
        i += 1
else:
    while i < n-2:
        if i == n-3:
            ans += t[i]
        else:
            ans += t[i]*2
        i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
As.sort(reverse=True)
from heapq import heappush, heappop

first = (As.pop(0))
hq = []
if N<2:
    print(0)
else:
    ans = 0
    second = As.pop(0)
    ans += first
    heappush(hq, (-second, -first))
    for a in As:
        s, f = heappop(hq)
        ans -= s
        heappush(hq, (-a, s))
        heappush(hq, (-a, f))

print(ans)

Submission status: Wrong Answer

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

for i in range(2, N):
    ans += A[tmp]
    if i % 1 == 0 and i != 1:
        tmp += 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    ans = 0
    m = 10 ** 10
    for i in range(N):
        if i == 0:
            m = min(m, A[i])
        else:
            ans += m
            m = min(m, A[i])

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    As = sorted(A)

    res = 0
    pre = As[N-1]

    for i in range(1,N):
        res += As[i]

    print(res)



main()

Submission status: Wrong Answer

Solution code:
def resolve():
    import sys
    sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
    to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
    print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

    # 入力を整数に変換して受け取る
    def input_int(): return int(input())

    def map_int_input(): return map(int, input())

    MII = map_int_input

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

    def MII_to_index(): return map(to_index, input())

    def MII_split_to_index(): return map(to_index, input().split())

    # 入力全てを整数に変換したものの配列を受け取る
    def list_int_inputs(): return list(map(int, input()))

    LII = list_int_inputs

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

    # 2次元リスト化
    def LII_2D(rows_number): return [LII() for _ in range(rows_number)]

    def LII_split_2D(rows_number): return [LII_split() for _ in range(rows_number)]

    from collections import deque
    N = input_int()
    friendlinesses = LII_split()

    s_fris = sorted(friendlinesses, reverse=True)

    queue = deque()
    queue.append(s_fris.pop(0))
    # print(s_fris)
    ans = 0
    for friendliness in s_fris:
        # print(friendliness)
        ans += queue.pop()
        queue.append(friendliness)
        queue.append(friendliness)
    print(ans)
    
resolve()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input().split(' ')
a.sort(reverse=True)
sum=int(a[0])
for i in range(0,n):
    a[i]=int(a[i])
for i in range(1,int(n/2)):
    sum+=2*a[i]
if(n%2!=0):
    sum+=a[int(n/2)]
print(sum)

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


last_x = A[0]
last_y = A[0]
ans = 0
cnt = 1
for i in range(1, n):
  if last_x>last_y:
    ans += last_x
    last_x = A[i]
    if cnt<2:
      lasy_y = A[i]
  else:
    ans += last_y
    last_y = A[i]
    if cnt<2:
      last_x = A[i]
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import sys

def main():

    n = int(input())
    a = list(map(int, input().split()))
    list.sort(a,reverse=True)
    ans = sum(a)-a[-1]
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
input=sys.stdin.readline

def main():
  N = int(input())
  A = list(map(int, input().split(' ')))
  A = sorted(A, reverse=True)
  print(A[0] + A[1]*(len(A)-2))

if __name__=='__main__':
  main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import heapq

N = int(input())
A = [-int(x) for x in input().split()]
A.sort()
pq = []
heapq.heapify(pq)
heapq.heappush(pq, A[0])
ans = 0
for a in A[1:]:
    ans += heapq.heappop(pq)
    heapq.heappush(pq, a)
print(-ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(input())
A = [int(x) for x in stdin.readline().rstrip().split()]
A.sort(reverse=True)
ans = A[0]
cnt = 2
for i in range(1,N):
    ans += (A[i]*2)
    cnt += 2
    if cnt >= N:
        if cnt > N:
            ans -= A[i]
        break
if N == 2:
    ans = min(A)
print(ans)

Submission status: Wrong Answer

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

print(sum(a[1:]))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = sorted(a)
b.pop(0)
print(sum(b))

Submission status: Wrong Answer

Solution code:


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

if n == 2:
    print(max(A))
    exit()

A.sort()
B = A[::-1]
# print(B)
ans = 0
print(sum(B) - B[-1] - B[-2] + B[1])

Submission status: Wrong Answer

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

a.sort()

total = 0
for i in range(1, n):
    total += a[i]

print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A.sort(reverse=True)
#print(A)
ans = 0
for i in range(N-1):
  ans += A[i]
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import math


def minu_int(i):
    return -1*int(i)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


N = z()
A = zz()

A = sorted(A, reverse=True)
# heapq.heapify(A)
# ans = 0
ans = sum(A[1:])
# for i in range(N):
#     ans +=
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

score_list = [0]
for i in range(1, len(A)):
    score_list.append(A[i])
    score_list.append(A[i])
    
print(sum(score_list[:n-1]))

Submission status: Wrong Answer

Solution code:
from sys  import stdin,stdout

import bisect
import math
def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def soe(limit):
    l=[1]*(limit+1)
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0

    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
            n=n-1
        else:
            a=(a*a)
            n=n>>1
    return r

m=(10**9 +7) 
def solve():
    n=inp()
    l=li()
    s=sum(l)
    c=0
    x=[]
    d={}
    for i in l:
        if i in x:
            if d[i]==0:
                d[i]+=1
                c+=1
        else:
            x.append(i)
            d[i]=0
        
    print(s-c)
    
            
        
    

solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A.sort(reverse=True)

Sum = 0

for i in range(N-1):
    if i < 2:
        Sum += A[i]
    else:
        Sum += A[(i+2)//2]
        
print(Sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a1 = sorted(a)
a1.pop(0)
print(sum(a1))

Submission status: Wrong Answer

Solution code:
# Contest No.: ABC173
# Problem No.: D
# Solver:      JEMINI
# Date:        20200705

import sys
import heapq

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

    nums.sort()
    ans = 0

    # initial
    temp = nums.pop()
    ans += temp
    n -= 2

    for i in range(n // 2):
        ans += nums[-i - 1] * 2

    if n % 2:
        ans += nums[-(n // 2)]
    
    
    print(ans)

    return

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:
#関数リスト
import sys
input = sys.stdin.readline

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

n = I()
mylist = LI()
mylist.sort(reverse=True)

result = mylist[0]
n -= 1

if n % 2!=0:
    for i in range(1,n-1,2):
        result += mylist[i]*2
    print(result)
else:
    for i in range(1,n-1,2):
        result += mylist[i]*2
    temp = (n-1)//2
    result += mylist[temp+1]
    print(result)

Submission status: Wrong Answer

Solution code:

n = int(input())
li = list(map(int,input().split()))
li.sort()
li.reverse()
l = []
for i in range(n):
    if i==0:
        l.append(li[0])
    elif i==1:
        l.append(li[0])
    else:
        l1 = sorted(li)
        l1.reverse()
        a = l1[0]
        b = l1[1]
        l.append(min(a,b))
l.pop(0)
print(sum(l))

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(input())
A = [int(x) for x in stdin.readline().rstrip().split()]
A.sort(reverse=True)
ans = A[0]
cnt = 2
for i in range(1,N):
    ans += (A[i]*2)
    cnt += 2
    if cnt >= N:
        if cnt > N:
            ans -= A[i]
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as dd
import heapq
N = int(input())
a = list(map(int,input().split()))
res = 0
a = sorted(a, reverse=True)
dic=dd(list)
ls = [a[0]]
heapq.heapify(ls)
for val in a[1:]:
    tmp = heapq.heappop(ls)
    res += tmp
    heapq.heappush(ls,val)
    heapq.heappush(ls,val)
print(res)

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
from heapq import heappush

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    N = ii()
    A = lmi()

    h = []
    for a in A:
        heappush(h, a)

    print(sum(h[1:]))

    return

main()

Submission status: Wrong Answer

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

min_a = min(A)

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
c = 0
r = a.pop(0)
l = r
for i in a:
    if r < l:
        c += r
        r = i
    else:
        c += l
        l = i
print(c)

Submission status: Wrong Answer

Solution code:
import heapq
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    _ = int(input().strip())
    A_l = [-int(i) for i in input().strip().split()]
    heapq.heapify(A_l)

    used = []
    ans = 0
    # 初回と２回目は固定行動
    m1 = -1 * heapq.heappop(A_l)
    used.append(m1)
    m2 = -1 * heapq.heappop(A_l)
    used.append(m2)
    ans += m1
    prev = m2
    while A_l:
        m = -1 * heapq.heappop(A_l)
        ans += prev
        prev = m

    return ans


if __name__ == "__main__":
    print(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()
    friendliness = deque(friendliness)
    tmp_queue = deque()
    ans = friendliness.pop()
    tmp_queue.appendleft(ans)
    tmp_queue.appendleft(friendliness.pop())
    while friendliness:
        ans += tmp_queue[0]
        tmp_queue.pop()
        tmp_queue.appendleft(friendliness.pop())
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
from sys import setrecursionlimit
import heapq

n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))
a.sort(reverse=True)

point = a[0]

b = a[1]
c = a[1]

for i,j in enumerate(a[2:]):
    if i%2 == 0:
        point += b
        b = j
    else:
        point += c
        c = j

print(point)

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    m = 10**9+1
    s = 0
    for a in map(int,input().split()):
        m = min(m, a)
        s += a
    print(s-m)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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


def solve(lst):  # fix inputs here
    # console("----- solving ------")
    lst = sorted(lst)[::-1]
 
    res = lst[0]
    # print(lst)
 
    for i in range(2, len(lst)):
        res += lst[i-1]
        # print(res)
 
    # return a string (i.e. not a list or matrix)
    return res


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


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

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

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

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

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

    # Codeforces - no case number required
    print(res)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N = k()
A = l()
A.sort()
A.reverse()
B = []

for i in range(N-1):
    B.append(A[i])
    B = sorted(B,reverse =True)
    if i == 0:
        ans += B[0]
    else:
        ans += B[1]

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math  # noqa: F401
from collections import deque  # noqa: F401
from typing import Deque, Dict, List, Optional, Tuple, Union  # noqa: F401


def main(N: int, A: List[int]):
    ans = 0
    A = sorted(A, reverse=True)
    for i, a in enumerate(A[1:], start=1):
        ans += A[i - 1]
    print(ans)


if __name__ == "__main__":
    N = int(input())
    A: List[int] = list(map(int, input().split()))
    main(N, A)

Submission status: Wrong Answer

Solution code:
N=int(input())
input1=list(map(int,input().split()))
max1=0
for  i in input1:
	if sum(input1)-i >max1:
		max1=i 
print(max1)

Submission status: Wrong Answer

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

ans = int(l[0])

for i in range(2,n):
    ans += int(min(l[i-1],l[i-2]))
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(1,N):
  ans += A[i]
print(ans)

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

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

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

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

input = sys.stdin.readline

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

inf = float('inf')
mod = 1000000007

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

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

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

	kyoyou = 2

	for i,val in enumerate(A):
		#print(ans)
		if i == 0:
			maxs = val
			continue
		if i == 1:
			ans += maxs
			if val == maxs:
				kyoyou += 1
			else:
				maxs = val
		else:
			ans += maxs
			if val == maxs:
				kyoyou += 1
			else:
				counts += 1
			if counts == kyoyou:
				maxs = val
				counts = 0
				kyoyou = 2

	print(ans)




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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
# print(N)
# print(A)
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.sort()
ans = 0
for check,i in enumerate(a):
    if check == 0:
        continue
    ans += i
print(ans)