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: Accepted

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()
    num_list = i_list()

    co_list = Counter(num_list)

    count = 0

    num_list = list(set(num_list))
    num_list.sort(reverse=True)

    ans_list = []

    for i, num in enumerate(num_list):
        num_c = co_list[num]

        for _ in range(num_c*2):
            ans_list.append(num)
        if i == 0:
            ans_list.pop()

    for i in range(n-1):
        count += ans_list[i]
        
    print(count)
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque
scores = deque()

result = 0

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

scores.append(l[0])

for i in range(1, N):
    scores.append(l[i])
    scores.append(l[i])
    result += scores.popleft()

print(result)

Submission status: Accepted

Solution code:
import heapq

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

comf = [-a.pop()]
heapq.heapify(comf)
res = 0
for _ in range(n-1):
    v = a.pop()
    res -= heapq.heappop(comf)
    heapq.heappush(comf, -v)
    heapq.heappush(comf, -v)
print(res)

Submission status: Accepted

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

a.sort()
f = 1
ans = 0
while N>0:
    n = a.pop()
    cnt = 1
    while len(a) != 0 and n == a[-1]:
        a.pop()
        cnt += 1
    if N - (cnt*2 - f) <= 0:
        ans += (N-f) * n
    else:
        ans += (cnt * 2 - f) * n
    N -= cnt * 2 
    f *= 0

print(ans)

Submission status: Accepted

Solution code:
#abc173d.py
#これって大きい順に並び替えて、最大の人と２ばン目の人の間に入ればいいだけなのではないのか？

N=int(input())
Alist=list(map(int,input().split()))
Alist.sort(reverse=True)
kokochiyosa=Alist[0]
for i in range(1,N-1):
    kokochiyosa+=Alist[(i+1)//2]

print(kokochiyosa)

Submission status: Accepted

Solution code:
from collections import deque


def main():
    n = int(input())
    A = [int(e) for e in input().split()]

    A.sort(reverse=True)
    D = deque([A[0]])
    ans = 0
    for i in range(1, n):
        D.extend([A[i], A[i]])
        ans += D.popleft()

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

def m():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    ans = A[0]
    c = Counter(A[1:])
    d = list(c.items())
    d.sort(reverse=True, key=lambda x:x[0])
    tmp = []
    for k,v in d:
        for i in range((v-1)+(v+1)):
            tmp.append(k)
    ans += sum(tmp[:N-2])
    return ans
print(m())

Submission status: Accepted

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

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

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

ans = A[0]
for i in range(1, N-1):
    # print(i)
    index = (i + 1) // 2
    # print("index: {} v: {}".format(index, A[index]))
    ans += A[index]

print(ans)

Submission status: Accepted

Solution code:
import sys


def main():
    def readline_and_rstrip() -> str:
        s = sys.stdin.readline()
        return s.rstrip()

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

    a.sort(reverse=True)

    if n == 2:
        print(a[0])
    elif n == 3:
        print(a[0] + a[1])
    elif (n - 2) % 2 == 0:
        middle_len = (n - 2) // 2
        a_middle = a[1:1 + middle_len]
        print(a[0] + sum(map(lambda x: x * 2, a_middle)))
    else:
        middle_len = (n - 2) // 2
        a_middle = a[1:1 + middle_len]
        print(a[0] + sum(map(lambda x: x * 2, a_middle)) + a[1 + middle_len])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    A =LI()
    A.sort(reverse=True)
    ans = A[0] + sum(A[1:n//2])*2
    if n%2:
        ans += A[n//2]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

a.sort(reverse=True)

score = 0

m = int(n / 2)

for i in range(m):
  score += a[i] * 2

if n % 2 == 1:
  score += a[m]
  
score -= a[0]

print(score)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
b = a[0]
for i in range(2, n):
    b += a[i // 2]
print(b)

Submission status: Accepted

Solution code:
from collections import deque
from bisect import bisect_left
n = int(input())
a = sorted(list(map(int,input().split())),reverse=True)

c = 0
q = deque([a[0]])
for i in a[1:]:
    m = q.pop()
    c += m
    q.appendleft(i)
    q.appendleft(i)
print(c)

Submission status: Accepted

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

sA = sorted(A, reverse=True)

if N % 2 == 0:
    res = sum(sA[:N//2]) * 2 - sA[0]
else:
    res = sum(sA[:N//2]) * 2 - sA[0] + sA[N//2]

print(res)

Submission status: Accepted

Solution code:
n = int(input())
arr = sorted([int(x) for x in input().split()])
total = 0
x = n-2
c = 0
for i in range(2, n):
    total += arr[x]
    c += 1
    if c == 2:
        c = 0
        x -= 1
print(total+arr[-1])

Submission status: Accepted

Solution code:
n = int(input())

lst = list(map(int, input().split()))
lst = sorted(lst, reverse=True)
class Queue:
  def __init__(self):
    self.queue_lst = []
    self.first_flag = True
    self.count = 0
    self.index = 0
  
  def add(self, friend_val):
    if self.first_flag:
      self.queue_lst.append(friend_val)
      self.first_flag = False
    else:
      self.queue_lst.append(friend_val)
      self.queue_lst.append(friend_val)
      self.count += self.queue_lst[self.index]
      self.index += 1
  
queue = Queue()

for i in lst:
  queue.add(i)



print(queue.count)

Submission status: Accepted

Solution code:
import numpy as np
import math


def _run(N, As):
    As.sort(reverse=True)
    sum_value = 0
    for i in range(1, N):
        index = math.ceil((i - 1) / 2)
        sum_value += As[index]
    print(sum_value)
    # states = []
    # for i in range(N):
    #     max_value = 0
    #     max_index = 0
    #     for j in range(len(states)):
    #


def _main():
    N = int(input())
    As = list(map(int, input().split()))
    _run(N, As)


if __name__ == "__main__":
    _main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from itertools import combinations 
import sys
import math as mt
input=sys.stdin.buffer.readline  
t=1


#t=int(input())
for _ in range(t):
    n=int(input())
      
    #n,m,k=map(int,input().split())
    l=list(map(int,input().split()))
    l.sort(reverse=True)
    ans=l[0]
    cnt=0
    ind=1
    for i in range(2,n):
        if cnt==2:
            cnt=0
            ind+=1
        ans+=l[ind]
        cnt+=1
    print(ans)

Submission status: Accepted

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)
if (N == 2):
    print(max(A))
    exit()
elif (N == 3):
    print(sum(A[:2]))
    exit()
else:
    ans = A[0]
    index = 1
    for i in range(1, N-1):
        # print(A[index])
        ans += A[index]
        if (i % 2 == 0):
            index += 1
    print(ans)

Submission status: Accepted

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
            if conut==N:
                break
        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: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
a = LIST()
a.sort(reverse=True)
ans = a[0]
cnt = 0
idx = 1
for i in range(n - 2):
    ans += a[idx]
    cnt += 1
    if cnt == 2:
        cnt = 0
        idx += 1
print(ans)

Submission status: Accepted

Solution code:
import math

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

    A_sorted = sorted(A, reverse=True)
    ans = 0

    for i in range(math.ceil(N/2) - 1):
        ans += A_sorted[i]

    for i in range(math.ceil(N/2) - 1):
        ans += A_sorted[1+i]
    if N % 2 == 0:
        ans += A_sorted[N//2 - 1]

    print(ans)
    
main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
N=int(sys.stdin.readline().strip())
A=map(int, sys.stdin.readline().split())
A.sort(reverse=True)
N-=1
ans=0
for i,a in enumerate(A):
    if i==0:
        ans+=a
        N-=1
    else:
        if 2<=N:
            ans+=a*2
            N-=2
        elif N==1:
            ans+=a
            N-=1
        elif N==0:
            print ans
            quit()

Submission status: Accepted

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

if alen %2 == 1:
  s = 2* sum(a[::-1][ :(alen+1)//2 ]) - a[-1] - a[::-1][alen//2]
else:
  s = 2* sum(a[::-1][ :(alen)//2 ]) - a[-1] 
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
import heapq
def main():
    N = int(input())
    A_lsit = list(map(int, input().split()))
    A_lsit.sort(reverse=True)

    answer = A_lsit[0]
    A_heap = [-(A_lsit[1])]*2
    heapq.heapify(A_heap)
    for i in range(2, N):
        max_in_heap = -(heapq.heappop(A_heap))
        answer += max_in_heap
        heapq.heappush(A_heap, -(A_lsit[i]))
        heapq.heappush(A_heap, -(A_lsit[i]))
    print(answer)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

answer = 0
consume = N
for a in A:
    if consume == N:
        consume -= 2
        if N > 1:
            answer += a
        continue
    elif consume > 1:
        answer += a * 2
        consume -= 2
        continue
    elif consume == 1:
        answer += a
        consume -= 1
        continue
    else:
        break

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

A.sort(reverse=True)
confort_index = 1
now_confort_count = 2
ans = A[0]
for i in range(2,N):
  ans += A[confort_index]
  now_confort_count -= 1
  if now_confort_count == 0:
    confort_index += 1
    now_confort_count = 2

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int, input().split(" ")))
sorted_a_list = sorted(a_list, reverse=True)
total_comfort = 0
if n%2==0:
    right_index = n/2
    for i, i_comfort in enumerate(sorted_a_list):
        if i==right_index:
            break
        if i==0:
            total_comfort+=i_comfort
        else:
            total_comfort+=i_comfort*2
else:
    right_index = (n+1)/2
    for i, i_comfort in enumerate(sorted_a_list):
        if i==right_index:
            break
        if i==0 or i==right_index-1:
            total_comfort+=i_comfort
        elif i==right_index-1:
            total_comfort+=i_comfort
        else:
            total_comfort+=i_comfort*2
print(total_comfort)

Submission status: Accepted

Solution code:
import itertools
import copy
from collections import deque
import heapq
n = int(input())
a = list(map(int,input().split()))
a.sort()
a = a[::-1]
p = a[0]
c = 1
ans = 0
cnt = 0
for i in range(n-1):
    ans += p
    if c == 0:
        c += 1
    else:
        c = 0
        cnt += 1
        p = a[cnt]
    #print(ans,p)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

L = [A[0]]
i = 0
ans = 0
for a in A[1:]:
    ans += L[i]
    i += 1
    L.append(a)
    L.append(a)

print(ans)

Submission status: Accepted

Solution code:
from collections import deque
N=int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
q = deque([A[0]])
ans = 0
for i in range(1,N):
  ans += q.popleft()
  q.append( A[i] )
  q.append( A[i] )
print(ans)

Submission status: Accepted

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

A.sort(reverse=True)

h = []
heapq.heappush(h,(-1) * A[0])
ans = 0
for i in range(1,N):
  wk = heapq.heappop(h) * (-1)
  ans += wk
  heapq.heappush(h,(-1) * A[i])
  heapq.heappush(h,(-1) * A[i])
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
AtCoder :: Beginner Contest 173 :: Chat in a Circle
https://atcoder.jp/contests/abc173/tasks/abc173_d
"""
import sys
import heapq

def solve(players):
    """Solve puzzle."""
    players.sort(reverse=True)
    circle = []
    heapq.heappush(circle, -players[1])
    heapq.heappush(circle, -players[1])

    comfort = players[0]
    for player in players[2:]:
        spot = -heapq.heappop(circle)
        comfort += spot
        heapq.heappush(circle, -player)
        heapq.heappush(circle, -player)
    return comfort


def main():
    """Main program."""
    player_count = int(sys.stdin.readline())
    players = [int(i) for i in sys.stdin.readline().split()]
    print(solve(players))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque 
n = int(input())
a = list(map(int,input().split()))

a.sort()
fir = a[n-1]

sco = 0
sit = deque([fir])
for i in range(n-1):
    sco += sit.popleft()
    sit.append(a[n-i-2])
    sit.append(a[n-i-2])
print(sco)

Submission status: Accepted

Solution code:
import numpy as np

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

A = sorted(A, reverse=True)
A = np.array(A)

if N % 2 == 0:
  # # 偶数の場合
  end = (N - 2) // 2
  answer = A[0] + (A[1:end+1] * 2).sum()
else:
  # 奇数の場合
  end = (N - 2) // 2
  answer = A[0] + (A[1:end+1] * 2).sum() + A[end+1]

print(answer)

Submission status: Accepted

Solution code:
N  = int(input())
A = sorted([int(a) for a in input().split()], reverse=True)
cnt = N
if N == 2:
    ans = A[0]
else:
    ans = A[0]
    cnt = N - 2
    A = A[1:]
    chk = 0
    for a in A:
        if cnt == 0:
            break
        elif cnt == 1:
            ans += a
            break
        ans += 2*a
        cnt -= 2
print(ans)

Submission status: Accepted

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
dic = defaultdict(int)
dq = deque()
for i in range(n):
    #print(dq)
    if i == 0:
        dq.append(A[i])
    else:
        ans += dq.popleft()
        for j in range(2):
            dq.append(A[i])
print(ans)

Submission status: Accepted

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

n = int(input())

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

if n == 2:
    print(AS[0])
else:
    m = math.ceil(n / 2)
    ans = 0
    for i in range(m):
        if i == 0:
            ans += AS[0]
        elif i < m-1:
            ans += AS[i]*2
        else:
            if n % 2 == 0:
                ans += AS[i]*2
            else:
                ans += AS[i]
    print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# モジュールのインポート
import math
import numpy as np

# 標準入力を取得
N = int(input())
A = list(map(int, input().split()))

# 求解処理
A = sorted(A, reverse=True)
A = np.array(A)
ans = 2 * np.sum(A[:(N // 2)]) - A[0] + (N % 2) * A[math.floor(N / 2)]

# 結果出力
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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


sr = sorted(coms, reverse=True)

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

print(ans)

Submission status: Accepted

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


comfort = 0
for i in range(1, n):
    parent = i // 2
    comfort += as_[parent]

print(comfort)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
count = A[N-1]
i = 0
j = 0
if N == 2:
    print(A[1])
else:
    if (N-2) % 2 == 0:
        for i in range(0,(N-2)//2):
            count += 2 * A[N-2-i]
    else:
        for j in range(0,(N-2)//2):
            count += 2 * A[N-2-j]
        count += A[N-3-j]
    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
res = A[0]
i = 1
c = 2
while c < N:
    res = res + A[i]
    c = c + 1
    if c >= N:
        break
    res = res + A[i]
    c = c + 1
    if c >= N:
        break
    i = i + 1
    
print(res)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(map(int,input().split()),reverse=True)
p=0
for i in range(n//2):
    p+=a[i]
for i in range(1,n%2+n//2):
    p+=a[i]
print(p)

#print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
import math  # gcdもあるよ
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化

def main():
    n = int(input())
    A = list(map(int,input().split()))
    A.sort(reverse=True)
    ans = A.pop(0)
    if n % 2 == 0: #偶数
        ans += sum(A[: (n // 2 - 1)]) * 2
    else: # 奇数
        ans += sum(A[: (n // 2 - 1)]) * 2
        #print(ans)
        #print(A[n // 2 - 1])
        ans += A[n // 2 - 1]
    print(ans)
    return 0

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

A = A + A
A.sort(reverse=True)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
ans = A[N//2:]
if N%2 == 0:
    print(sum(ans)*2 - max(ans))
else:
    print(sum(ans)*2 - max(ans) - min(ans))

Submission status: Accepted

Solution code:

n=int(input())
a=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
a.sort(reverse=True)

asum=0
for i in range(1,n):
    ii=(i+2)//2
#    print(ii,a[ii-1])
    asum+=a[ii-1]
    
print(asum)

Submission status: Accepted

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

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

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)



if __name__ == '__main__':
    N = intinput()
    a_arr = list(mulinputs())
    l = len(a_arr)
    is_odd = l % 2
    a_arr.sort(reverse=True)

    # ans = a_arr.pop(0)
    # for _ in range(int(l//2)-1):
    #     ans += (a_arr.pop(0) * 2)
    # if is_odd:
    #     ans += a_arr.pop(0)
    # print(ans)
    idx = 0
    ans = a_arr[idx]
    idx += 1
    for i in range(int(l//2)-1): ans += (a_arr[idx+i])*2
    if is_odd:
        idx += int(l//2)-1
        ans += a_arr[idx]
    print(ans)