Problem:


Score: 400 points

Problem Statement

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

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

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

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

Constraints

All values in input are integers.

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

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the maximum total comfort the N players can get.

Sample Input 1

4
2 2 1 3

Sample Output 1

7

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

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

Sample Input 2

7
1 1 1 1 1 1 1

Sample Output 2

6



Sample input:
4
2 2 1 3


Sample output:
7

Submission status: Wrong Answer

Solution code:
N = int(input())
n = 0
A = list(map(int,input().split()))
cnt = int(0)
A.sort(reverse=True)
ans = 0
if N < 5:
  for num in range(N-1):
    ans += A[num]
else:
    while cnt<N-1:
      ans += A[n]
      cnt += 1
      n += 1
      if cnt >= N:
        break
      ans += A[n]
      cnt+=1
print(ans)

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

if N % 2 == 1:
    sm = B[0] + B[1] + sum(B[i]*2 for i in range(N//2) if 0 < i)
    print(sm)
else:
    sm = B[0] + sum(B[i]*2 for i in range(N//2) if 0 < i)
    print(sm)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

a = sorted(a,reverse=True)
ok = 0

for i in range(1, n):
    ok += a[i-1]

print(ok)

Submission status: Wrong Answer

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

class MM:
    def __init__(self, c_max, c_cnt):
        self.c_max = c_max
        self.c_cnt = c_cnt

def solve(N: int, A: "List[int]"):
    sl = list(reversed(sorted(A)))
    score = 0
    c_max = sl[0]
    h = {sl[0]: 1}
    queue = deque()
    queue.append(c_max)
    for i in range(1, len(sl)):
        score += c_max

        if c_max == sl[i]:
            h[c_max] += 1
        else:
            h[c_max] -= 1
            if sl[i] in h:
                h[sl[i]] += 1
            else:
                h[sl[i]] = 2
                queue.append(sl[i])

            if h[c_max] == 0:
                queue.popleft()
                c_max = queue[0]
        # print(f'{i} {sl[i]} {c_max} {h}')
    print(score)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
l1=list(map(int,input().split()))
l1.sort()
l1.reverse()
k=l1[0]
comfort=0
for i in range(0,n-1):
    if l1[i]==l1[i+1]:
       comfort+=min(l1[i],k)
    else:
        comfort+=k
        k=l1[i]
print(comfort)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
ret = A[0]
count = 1
i = 1
while True:
  if N == count:
    break
  if N - count == 1:
    ret += A[i]
    break
  ret += (A[i] * 2)
  count += 2
  i += 1
print(ret)

Submission status: Wrong Answer

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

N = int(input())
A = [int(s) for s in input().split()]
A_s = zip(list(range(N)), A)
A_s = sorted(A_s, key=lambda x: x[1], reverse=True)

kokoti = 0
kokoti += A_s[0][1]

#h = list(map(lambda x: (-1*x[0], x[1]), A_s))
h = []
heapq.heapify(h)  # リストを優先度付きキューへ
heapq.heappush(h, (-A_s[1][1]))

for i in range(2, N):
    x = heapq.heappop(h)  # 最大値の取り出し
    kokoti += (-x)
    #heapq.heappush(h, (-A_s[i][1], (a[0], A_s[i][0])))  # 要素の挿入
    #heapq.heappush(h, (-A_s[i][1], (A_s[i][0], a[1])))
    heapq.heappush(h, (-A_s[i][1]))  # 要素の挿入
    heapq.heappush(h, (-A_s[i][1]))

print(kokoti)

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])
for i in a[2:]:
    ans+=d.popleft()
    d.append(i)
    d.append(i)
print(ans)

Submission status: Wrong Answer

Solution code:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N = next(it)
    A = list(it)

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

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())
n = 0
A = list(map(int,input().split()))
cnt = int(0)
A.sort(reverse=True)
ans = 0
if N < 5:
  for num in range(N-1):
    ans += A[num]
else:
    while cnt!=N:
      ans += A[n]
      print(A[n])
      cnt += 1
      n += 1
      if cnt == N:
        break
      ans += A[n]
      print(A[n])
      cnt+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l1=list(map(int,input().split()))
l1.sort()
l1.reverse()
k=l1[0]
comfort=0
for i in range(1,n-1):
    if l1[i]==l1[i+1]:
       comfort+=min(l1[i],k)
    else:
        comfort+=l1[i]
        k=l1[i]
print(comfort)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)
    score = 0
    if not len(A) < 2:
        min_max_list = [0] * n
        min_max_dict = {A[1]: 2}
        max_value = A[1]
        score = A[0]
        for num, a in enumerate(A[2:]):
            score += max_value
            min_max_dict[max_value] -= 1
            if a in min_max_dict:
                min_max_dict[a] += 1
            else:
                min_max_dict[a] = 1
            if min_max_dict[max_value] == 0:
                del(min_max_dict[max_value])
                max_value = max(min_max_dict.keys())
    print(score)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
from collections import Counter
from operator import itemgetter
c=Counter(a)
ans=0
cnt=n-1
for k,v in reversed(sorted(c.items(),key=itemgetter(0))):
    if cnt<=0:break
    t=min(cnt,v)
    cnt-=t
    ans+=k*t
print(ans)

Submission status: Wrong Answer

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

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

N = int(input())
A = [int(_) for _ in input().split()]
A = sorted(A, reverse=True)

ret = A[0]
ct = 0
ni = []
for i in A[1:-1]:

    ni += [i]

    if ct + 1 == 2:
        ni = ni[1:]

    ret += ni[0]
    ct = (ct + 1) % 2

print(ret)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)[::-1]
l = [0] * (n)
s = 0
e = n - 1

for i in range(n):
    if  i % 2 != 0:
        l[s] = a[i]
        s += 1
    else:
        l[e] = a[i]
        e -=1

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

Submission status: Wrong Answer

Solution code:
N = int(input())
point = list(map(int,input().split(" ")))
point.sort(reverse=True)
ans = point[0]
cnt = 1
for i in range(N-2):
  ans += point[cnt]
  if i%2==0 and i!=0:
    cnt += 1

print(ans)

Submission status: Wrong Answer

Solution code:
#! env/bin/local python3
# -*- coding: utf-8 -*-


def main():

    n = int(input())
    friends = sorted(list(map(int, input().split())))

    if n == 0 or n ==1:
        print(n)
        return None
    if n == 2:
        print(friends.pop())
        return None

    score = 0

    queue = []
    queue += [friends.pop()]

    for i in range(len(friends)):
        f = friends.pop()
        if f == queue[0]:
            score += f
            queue += [f]
        else:
            score += queue[0]
            queue = queue[1:]
            queue.append(f)

    print(score)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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])+sum(l_sort[1:(l_len//2)])+l_sort[(l_len//2)]
else:
    ans = sum(l_sort[:(l_len//2)])+sum(l_sort[1:(l_len//2)+1])

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l1=list(map(int,input().split()))
l1.sort()
l1.reverse()
k=l1[0]
comfort=0
for i in range(0,n-1):
    if l1[i]==l1[i+1]:
       comfort+=min(l1[i],k)
    else:
        comfort+=l1[i]
        k=l1[i]
print(comfort)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import 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

    ans+=ListA[0]
    for i in range(N-2):
        ans+=min(ListA[i],ListA[i+1])

    print(ans) 



resolve()

Submission status: Wrong Answer

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

a.sort(reverse=True)
sum=0
if n==2:
    sum+=a[0]
elif n==3:
    sum+=a[0]+a[1]
elif n>=4:
    sum+=a[0]+a[1]
    #print(sum)
    for i in range(4,n+1):
        sum+=a[i-2]
print(sum)

Submission status: Wrong Answer

Solution code:
import sys
import os
import itertools
import numpy as np
from collections import deque

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

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

    A.sort(reverse=True)
    # print(A)
    # s=sum(A)-min(A)
    A_set=list(set(A))
    A_set.sort(reverse=True)
    set_p=0
    # print(A_set)

    ans=0
    print(A_set)
    print([0]*len(A_set))
    arc={k: 0 for k in A_set}
    # print(type(arc))
    # print(A[0])
    arc[A_set[0]]=arc[A_set[0]]+1
    max=A_set[0]    #取得できる最大の心地よさ
    for a in A[1:]:
        # print(arc)
        arc[a]+=2

        ans+=max
        arc[max]-=1
        if arc[max]==0:
            set_p+=1
            max=A_set[set_p]


    print(ans)
    # comfort

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
_max = A.count(A[0])
d = defaultdict(int)
for a in A:
    d[a] += 1
waku = []
for k, v in d.items():
    if A[0] == k:
        for _ in range(v):
            waku.append(k)
    else:
        for _ in range(v+1):
            waku.append(k)
if d[A[0]] != 1:
    for _ in range(d[A[0]]-1):
        waku.append(A[0])
waku.sort(reverse=True)
ans = 0
for i in range(n-1):
    ans += waku[i]
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()
ans = b + a
B = [b,c,c]
B.sort()
i = 0
while A:
    a = A.pop(0)
    b = B.pop(0)
    ans += b
    B.append(a)
    B.append(a)
    B.sort()
print(ans)

Submission status: Wrong Answer

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

A.sort(reverse=True)
wa=A[0]
i=0
amari=len(A)%2

while(1):

    if(amari==0):

        if(len(A)-1==1+2*i):
            print(wa)
            break
        wa=A[1+2*i]*2+wa


    elif(amari==1):
        if(len(A)-2==1+2*i):
            print(A[1+2*i-1]+wa)
            break
        wa=A[1+2*i]*2+wa

    i=i+1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b

# 貪欲に大きい方だと思うんだけど違うのかな
# 貪欲でない反例 (わからん)


N = a_int()
A = ints()
A.sort()
print(sum(A[1:]))

Submission status: Wrong Answer

Solution code:

def abc173_d():
    import sys
    sys.setrecursionlimit(4100000)
    N = int(input())
    a =  list(map(int,input().split()))


    a = sorted(a,reverse=True)

    Enkan = [a[0],a[1]]





    gokei = []
    def saiki(i,suma,Enkan):
        
        if i == N:
            gokei.append(sum(suma))
            return
        else:
            for k in range(len(Enkan)):

                if k != len(Enkan)-1:
                    suma.append(min(Enkan[k],Enkan[k+1]))
                    Enkan.insert(k,a[i])
                    saiki(i+1,suma,Enkan)
                    del Enkan[k]
                    del suma[-1]
                else:
                    suma.append(min(Enkan[-1],Enkan[0]))
                    Enkan.insert(0,a[i])
                    saiki(i+1,suma,Enkan)
                    del Enkan[0]
                    del suma[-1]

    saiki(2,[3],[a[0],a[1]])
    print(max(gokei))



abc173_d()

Submission status: Wrong Answer

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

s_A_list = sorted(A_list)

del s_A_list[0]

print(sum(s_A_list))

Submission status: Wrong Answer

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

a_sort = sorted(a,reverse=True)

list = [a_sort[0]]
for i in range((n - 1) // 2):
    list.append(a_sort[i + 1])
    list.append(a_sort[i + 1])
list_2 = list[0 : n]
print(sum(list_2))

Submission status: Wrong Answer

Solution code:
import numpy as np
def main():
  n = int(input())
  a = list(map(int, input().split()))
  a=sorted(a)
  
  place = []
  result = a.pop()
  place.append(a.pop())
  
  for _ in range(len(a)):
    cur = a.pop()
    if place[0] > cur:
      result += place.pop()
      place.append(cur)
    else:
      result += place[0]
      place.append(cur)
  print(result)
main()

Submission status: Wrong Answer

Solution code:
def main():

    n = int(input())
    a = list(map(int, input().split()))
    list.sort(a,reverse=True)
    ans = a[0]
    
    if (n == 2):
        print(ans)
    else:
        if n % 2 == 1:
            s = n-1
        else:
            s = n
        for i in range(s-3):
            if i != 0 :
                ans += (a[i]*2)
    if n % 2 == 1:
        ans += a[n-4]
    print(ans)
        
if __name__ == "__main__":
    main()

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():
    input()
    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:
person = int(input())
f = list(input().split(" "))
for i in range(person):
    f[i] = int(f[i])
f = sorted(f,reverse = True)

happy = 0
a = []

a.append(f[0])
a.append(f[1])
happy += f[0]

print(a)

if person > 2:
    for i in range(2,person):
        x = 0
        y = 0
        for j in range(len(a)-1):
            if a[j] <= a[j+1]:
                if x < a[j]:
                    x = a[j]
                    y = j + 1
            else:
                if x < a[j+1]:
                    x = a[j+1]
                    y = j + 1
        if a[len(a)-1] <= a[0]:
            if x < a[len(a)-1]:
                x = a[len(a)-1]
                y = 0
        else:
            if x < a[0]:
                x = a[0]
                y = 0
        print(x)
        print(y)
        a.insert(y,f[i])
        happy += x

        print(a)
        print(happy)

Submission status: Wrong Answer

Solution code:
N = input()
li = [int(s) for s in input().split(" ")]
li.sort(reverse=True)
result = 0
i = 1
while True:
    if i >= len(li):
        break
    if li[i-1] == li[i]:
        result += li[i-1]
        del li[-1]
    result += li[i-1]
    i += 1
print(result)

Submission status: Wrong Answer

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

ans=0
ans_list=[]
for i in range(N):
    if i == 0:
        ans+=0
        ans_list.append(A[i])
    elif i== 1:
        ans+=A[i-1]
        ans_list.append(A[i])
    else:
        ans+=ans_list[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 -1
print(ans)

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-1]
print(t)

Submission status: Wrong Answer

Solution code:
def main():

    n = int(input())
    a = list(map(int, input().split()))
    list.sort(a,reverse=True)
    print(a)
    ans = a[0]
    
    if (n == 2):
        print(ans)
    else:
        if n % 2 == 1:
            s = n-1
        else:
            s = n
        for i in range(s-3):
            if i != 0 :
                ans += (a[i]*2)
    if n % 2 == 1:
        ans += a[n-4]
    print(ans)
        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
Mylist = input().split()
Mylist = [int(s) for s in Mylist]
Mydict = collections.Counter(Mylist)

ANS = 0
lastKey = 0
amari = 0

for keys in Mydict.keys():
    tukaukazu = amari-Mydict[keys]
    if tukaukazu > 0:
        ANS += lastKey*Mydict[keys]
        amari = tukaukazu
    else:
        ANS += lastKey*amari + keys*-1*tukaukazu
        amari = -1*tukaukazu
        lastKey = keys

print(ANS-min(Mylist))

Submission status: Wrong Answer

Solution code:
import collections,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
A = sorted(LI())[::-1]
deque = collections.deque()
deque.append(A[0])
ans = 0
for x in A[1:]:
    deque.append(x)
    if set(deque)==1:
        ans += x
    else:
        ans += deque.popleft()

print(ans)

Submission status: Wrong Answer

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

A = sorted(A, reverse=True)

result = A[0]
cnt =1
position = 1
flag = 0
while cnt<N:
    if flag < 2:
        result += A[position]
        flag += 1
    else:
        flag = 0
        position += 1
        cnt -= 1
    cnt += 1

print(result)

Submission status: Wrong Answer

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import random
import copy

N = int(input())
data = input().split()
man = [int(i) for i in data]
conf = []


for i in range(math.factorial(N)):
  man2 = copy.deepcopy(man)
  random.shuffle(man2)
  cnt = man2[(-1)%N]
  for j in range(2,N):
    cnt += min(man2[(j-1)%N],man2[(j+1)%N])
  conf.append(cnt)
    
MAX = max(conf)
print(MAX)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

A.sort()
A.reverse()

ans = 0

if len(A) == 1:
  print(A[0])
  exit()
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:
n = int(input())
aList = list(map(int, input().split()))
aList.sort(reverse=True)
s = 0
for i in range(n-1):
    s += min(aList[i], aList[i+1])
print(s)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
import string
def main():  #startline-------------------------------------------
    n = int(input())
    a = list(map(int, input().split()))
    c = Counter(a)
    tmp = 0
    ans = 0
    cdic = list(c.keys())
    cdic.sort(reverse=True)
    lc = len(cdic)
    if len(set(a)) == 1:
        print(sum(a) - min(a))
        exit()
    else:
        for i in range(lc-1):
            tmp += c[cdic[i]]
            if tmp >= n:
                ans += n - (tmp - c[cdic[i]]) * cdic[i]
                break
            else:
                ans += tmp * cdic[i]  #今までの累積分足す
    print(ans - max(c.values()))

if __name__ == "__main__":
    main() #endline===============================================

Submission status: Wrong Answer

Solution code:
N = int(input())
n = int(N)
A = list(map(int,input().split()))
cnt = int(0)
A.sort(reverse=True)
ans = 0
if N < 5:
  for num in range(N-1):
    ans += A[num]
else:
    while cnt!=N:
      ans += A[n-1]
      cnt += 1
      n -= 1
      if cnt == N:
        break
      ans += A[n-1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))[::-1]
ans = 0
nxt = a[0]
cnt = 0

for i in range(len(a)-2):
    ans += nxt
    if nxt != a[i+1]:
        nxt = a[i+1]
    else:
        for j in range(i, len(a)-2):
            if nxt == a[i+1]:
                cnt += 1
                i += 1
            else:
                break
        ans += cnt*nxt
        cnt = 0

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ans=A[0]
if N%2==0:
  for i in range(1,(N-2)//2+1):
    ans+=A[i]*2
else:
  for i in range(1,(N-2)//2):
    ans+=A[i]*2
  else:
    ans+=A[i+1]
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 = B[-1]

for x in reversed(range(len(sorted(B)))):
    if x == 1:
        break

    if B[x] >= B[x-1]:
        comfort += B[x-1]
    elif B[x] <= B[x-1]:
        comfort += B[x]

print(comfort)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]
    A.sort(reverse=True)

    ans = A[0]
    n = 1
    cnt = 0
    while cnt <= N-2:
        for j in range(2):
            ans += A[n]
        n += 1
        cnt += 1
    
    print(ans)


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+1:n//2+2])
    print(bbb*2+ccc+max(a1)*bb)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a).most_common()
ans = 0
for i in range(len(c) - 1):
    if c[i][1] > c[i + 1][1]:
        ans += c[i][0] * c[i + 1][1]
    else:
        ans += c[i][0] * c[i][1] + (c[i][1] - c[i + 1][1]) * c[i][0]
print(ans)

Submission status: Wrong Answer

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

A.sort()
A.reverse()

total = A[0]
num = 1
num_list = []

for i in range((N-1)//2):
  num_list.append(i+1)
  num_list.append(i+1)
  
if N % 2 == 1:
  num_list.append(i+2)
  
#print(num_list)

for i in num_list:
  total += A[i]
  
    
  
print(total)

Submission status: Wrong Answer

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

ans = 0
A.sort(reverse=True)
#print(A)
for i in range(1,N):
    if i == 1:
        ans += A.pop()
        continue
    if i % 2 != 0:
        ans += A[0]
    else:
        ans += A.pop()
#print(A)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
cc = []
b = len(a) + 1
bb = b // 2
amari = b % 2
for i in range(bb):
  cc.append(a[-i])
  
print(2 * sum(cc) - a[-1] - (1- amari) * a[-bb])

Submission status: Wrong Answer

Solution code:
import heapq
n = int(input())
a_lst = list(map(int, input().split(" ")))

a_lst.sort(reverse=True)


result = 0
heap = []
heapq.heappush(heap,a_lst[0])

for i in a_lst[1:]:
	now_max = heapq.heappop(heap)
	result += now_max
	heapq.heappush(heap, i)
	heapq.heappush(heap, i)

print(result)

Submission status: Wrong Answer

Solution code:
N=int(input())

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

A=sorted(A)

ans=0
ls=[]
pt=[]

first=A.pop()
ls.append(first)
pt.append(first)

ans=0

for i in range(N-1):
    max_pt=max(pt)
    for j in range(len(ls)):
        if pt[j]==max_pt:
            ans+=pt[j]
            temp=A.pop()
            ls.insert(j,temp)
            if j==0:
                pt[-1]=temp
            else:
                pt[j-1]=temp
            pt[j]=temp
            break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
*A, = map(int, input().split())
A.sort(reverse=True)
chk = []
chk.append(A[0])
two = A.count(A[1])
chk.extend([A[1] for _ in range(((two + 1) * 2) - 2)])
if len(A) >= 2:
    for i in range(2, N):
        chk.extend([A[i] for _ in range(2)])
ans = 0
for i in range(N-1):
    ans += chk[i]
print(ans)

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

result = A[0]
cnt =1
position = 1
flag = 0
while cnt<N:
    if flag < 2:
        result += A[position]
        flag += 1
    else:
        flag = 0
        position += 1
        cnt -= 1
    print(result)
    cnt += 1

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

a.sort(reverse=True)

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