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())
a = list(map(int,input().split()))
print(sum(a) - min(a))

Submission status: Wrong Answer

Solution code:

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

A.sort(reverse=True)

ans=A[0]

if N%2==0:
    mat=N//2
    for i in range(mat-1):
        ans+=2*A[1+i]
else:
    mat=(N-1)//2
    for j in range(mat-1):
        ans+=2*A[1+j]
    ans+=A[mat-1]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
p = 0
ans = 0
for i in range(len(A)):
    if i == 2 or not i % 2 == 0:
        p = A.pop()
    ans += p
print(ans)

Submission status: Wrong Answer

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

# フレンドリーさが高い人から順に集まるようにする
ans = sum(A) - min(A)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

ans = a[0]
for i in range(2, n):
    ans += a[math.ceil(i / 2)]

print(ans)

Submission status: Wrong Answer

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

x=A.pop(0)
conf=0
for i in A:
  conf+=x
  x=i
  
print(conf)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
p = 0
ans = 0
l = (N+1) // 2
for i in range(l+1):
    if i == 2 or not i % 2 == 0:
        p = A.pop()
    if i == 0 or i == 1:
        ans += p
    elif not N%2==0 and l == i:
        ans += p
    else:
        ans += p*2
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(sum(ai[0:-1]))

Submission status: Wrong Answer

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


def solve(N: int, A: "List[int]"):
    sl = list(reversed(sorted(A)))
    score = 0
    circle = []

    c_max = sl[0]
    c_cnt = 1
    for i in range(1, len(sl)):
        score += c_max
        if c_max == sl[i]:
            c_cnt += 1
        else:
            c_cnt -= 1
            if c_cnt == 0:
                c_max = sl[i]
                c_cnt = 2



    # queue = deque()
    # for i in range(len(sl)):
    #     if i > 0:
    #         score += queue[0]
    #         if sl[i] < queue[0]:
    #             queue.popleft()
    #     queue.append(sl[i])

        # circle.append(sl[i])

    # for i in range(len(sl)):
    #     if i > 0:
    #         score += min(circle[0], circle[len(circle)-1])
    #     circle.append(sl[i])

    # print(sl)
    # print(circle)
    print(score)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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())
A=list(map(int,input().split()))
A.sort(reverse=True)
P=A[0]
if N==2:
  print(P)
  exit()
P+=A[1]
for i in range(3,N):
  P+=A[((i>>1)<<1)-1]
print(P)

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:
#! /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)

center = A[0]
l, r = center, center

ret = 0
for i in A[1:]:
    c = i
    ret += min(l, r)

    if l > r:
        l = c
    else:
        r = c

print(ret)

Submission status: Wrong Answer

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

# フレンドリーさが高い人から順に集まるようにする
ans = sum(A) - min(A)

Submission status: Wrong Answer

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

for i in range(1, (N - 2) // 3 + 1):
    sum += 3 * A[i]

if (N - 2) % 3 == 1:
    sum += A[(N - 2) // 3 + 1]
elif (N - 2) % 3 == 2:
    sum += 2 * A[(N - 2) // 3 + 1]

print(sum)

Submission status: Wrong Answer

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

A_sorted = sorted(A)
del A_sorted[0]

sum = 0
for i in range(N-1):
    sum = sum + A_sorted[i]

print(sum)

Submission status: Wrong Answer

Solution code:
from collections import deque
n=int(input())
a=sorted([int(i) for i in input().split()])[::-1]

if n==2:
    print(a[0])
else:
    b=deque([a[1],a[2]])
    ans=a[0]+a[1]
    minlist=[min(b)]
    j=0
    for i in range(n-3):
        if j==0:
            j+=1
            ans+=b[0]
            b+=[a[i+2]]
        else:
            j=0
            ans+=b[0]
            b.popleft()
            b+=[a[i+2]]
    print(ans)

Submission status: Wrong Answer

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

confortability = sorted(A,reverse=True)
neighbours = 0
idx = 0
ans = 0
for i, conf in enumerate(confortability):
    if i == 0:
        continue
    if neighbours < 1:
        print(confortability[idx])
        ans += confortability[idx]
        neighbours += 1
    else:
        idx += 1
        print(confortability[idx])
        ans += confortability[idx]
        neighbours = 0

print(ans)

Submission status: Wrong Answer

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

A.sort()

score = 0

for i in A:
  N -= 1
  if(N==0):
    break
  score += i
  N -= 1
  if(N==0):
    break
  score += i
  
print(score)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import deque
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


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


def readstrs():
    return input().split()


def main():
    N = readint()
    A = deque(sorted(list(readnums()), reverse=True))

    ans = 0
    m = int(math.log2(N))
    n1 = N - 2 ** m if N - 2 ** m <= 2 ** (m + 1) - N else 2 ** (m + 1) - N
    n2 = ((N - 1) - 1 - n1) // 2
    ans += A[0]
    A.popleft()
    for _ in range(n2):
        ans += A[0] * 2
        A.popleft()

    for _ in range(n1):
        ans += A[0]
        A.popleft()

    print(ans)


if __name__ == "__main__":
    main()

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 heapq

N = int(input())
A = list(map(int, input().split()))
A = list(map(lambda x: x * (-1), A))

heapq.heapify(A)

ans = 0
N -= 2
ans += heapq.heappop(A) * (-1)

if N == 0:
    print(ans)
    exit()
elif N == 1:
    ans += A[0]
    print(ans)
    exit()
elif N >= 2:
    q = N // 2
    r = N % 2
    for i in range(1, q + 1):
        max_n = heapq.heappop(A) * (-1)
        ans += 2 * max_n
    if r == 1:
        ans += A[0]
    print(ans)

Submission status: Wrong Answer

Solution code:
## coding: UTF-8
N = int(input())
A = list(map(int,input().split()))

A = sorted(A, reverse = True)
#print(N, A)

ans = 0

if(N == 2):
    print(A[0])
elif(N == 3):
    print(A[0] + A[1])
elif(N == 4):
    print(A[0] + A[1] + A[1])
elif(N == 5):
    print(A[0] + A[1] + A[1] + A[2])
else:
    ans += A[0]
    ans += A[1]
    for i in range(2, N-3):
        #print(i)
        ans += A[i]
    ans += A[1]
    ans += A[2]
    print(ans)

Submission status: Wrong Answer

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

for n in range(N-1):
  B+=[A[n]]
  if len(B)!=0:
    ans+=A[1+n]

if N%2==0:
  print(ans)
else:
  print(ans+A[-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int, input().split(' ')))
b = sorted(b, reverse=True)
r = b[0]
l = b[0]

point = b[0]
b.pop(0)

for i in range(a-2):
  if r >= l:
    l = b[i]
  elif l >= r:
    r = b[i]
  plus = min(r, l)
  point = point + plus

print(point)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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:
import sys
import math
# sys.stdin=open('input.txt','r')
# sys.stdout=open('output2.txt','w')
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007

n=ii1()
arr=iia()
arr.sort()
a=sum(arr)
print(a-arr[0])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

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

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
A = IL()
A.sort(reverse=True)

q = [A[1],A[1]]
ans = A[0]
for a in A[2:]:
  ans += q[0]
  heapq.heappop(q)
  heapq.heappush(q,a)
  heapq.heappush(q,a)
print(ans)

Submission status: Wrong Answer

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

import collections
N = int(input())
A = sorted(list(map(int, input().split())))[::-1]

C = collections.Counter(A)

if N == 2:
    print(A[0])
    exit()
ret = A[0]
cnt = 2

C = sorted(C.items())[::-1]
for n, c in C:
    if cnt + c > N:
        ret += n*(N-cnt)
        break
    else:
        ret += n*c*2
        cnt += n

print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def judge():
    ans = True
    return ans

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

sum = 0
val = False
d_max = 1
d_max2 = 1
for d in a:
    sum += d
    if d > d_max:
        d_max2 = d_max
        d_max = d
    if d > d_max2 and d_max > d:
        d_max2 = d
print (d_max + (n-2)*d_max2)

# 2番めに大きいやつは確実に選べるのでは？

Submission status: Wrong Answer

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

if n <= 3:
  print(a[:-1])
else:
  ans = sum(a[:2])
  for i in range(3, n):
    ans += max(a[i-2], a[i-1])
  print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split()))

    A.sort(reverse=1)
    players = [A[0], A[0]]
    ans = 0
    for a in A[1:]:
        if players[1] > players[-2]:
            ans += players[1]
            players = [players[0]] + [a] + players[1:]
        else:
            ans += players[-2]
            players = players[:-1] + [a] + [players[-1]]
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

class PriorityQueue:

    #初期化
    def __init__(self,heap):
        self.heap = heap
        heapify(self.heap)
    
    #値の追加
    def push(self,item):
        heappush(self.heap,item)
    
    #値の取り出し
    def pop(self):
        return heappop(self.heap)
    
    #値を追加して取り出し
    def pushpop(self,item):
        return heappushpop(self.heap,item)
    
    #データ構造の中身を見る
    def __call__(self):
        return self.heap
    
    #heapの長さ
    def __len__(self):
        return len(self.heap)


if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    heap = []
    q = PriorityQueue(heap)
    for i in range(n):
        q.push(-a[i])
    i = 0
    b =collections.deque()
    ans = 0
    while q:
        p = -q.pop()
        if i%2 == 0:
            if i>0:
                ans += min(b[0],b[-1])
            b.appendleft(p)
        else:
            if i == 1:
                ans += b[0]
            else:
                ans += min(b[0],b[-1])
            b.append(p)
        i+=1
    print(ans)

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:
N = int(input())
A = input().split()
A_int = []
con = 0
for i in range(N):
  A_int.append(int(A[i]))
A_int.sort()
del A_int[0]
for i in range(N-1):
  con += A_int[i] 
print(con)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a1 = sorted(a, reverse=True)
print(a1[1]*(n-2)+max(a1))

Submission status: Wrong Answer

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

a.sort(reverse=True)

temp = [a[0],a[1]]
count = temp[0]

for i in range(2, n):
  if temp[0] >= temp[1]:
    count += temp[1]
    temp[0] = a[i]
  else:
    count += temp[0]
    temp[1] = a[i]
    
print(count)

Submission status: Wrong Answer

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

if n == 2:
  print(a[0])
  exit(0)
if n == 3:
  print(a[0]+a[1])
  exit(0)
w = a[:3]
ans = a[0] + a[1]
i = 3
#print(w, ans, i, n)
while i < n:
  t = []
  for j in range(len(w)):
    if j == len(w)-1:
      ans += w[j]
    else:
      if w[j] > w[j+1]:
        ans += w[j+1]
      else:
        ans += w[j]
    t.append(w[j])
    t.append(a[i])
    i += 1
    if i >= n:
      break
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

    #print(x)
    #print(str(B[x]) + ' ' +str(B[x-1]))
    if B[x] >= B[x-1]:
        #print(str(B[x]) + ' ' + str(B[x - 1]))
        comfort += B[x-1]
    elif B[x] <= B[x-1]:
        #print(str(B[x]) + ' ' + str(B[x - 1]))
        comfort += B[x]

print(comfort)

Submission status: Wrong Answer

Solution code:
N = int(input())
FRI_STRING=input().split()
FRI = [int(s) for s in FRI_STRING]

import numpy as np
ARR = np.array(FRI)
ARR = np.sort(ARR)

count = 0
for i in ARR[1:]:
  
  count = count + i
  
print(count)

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

A_cnt = collections.Counter(A)
A_key = list(A_cnt.keys())[::-1]
A_val = list(A_cnt.values())[::-1]
total = 0
for i in range(len(A_val)):
    a_val = A_val[i]
    j = 0
    while a_val>0:
        if A_val[j]==0:
            j +=1
        else:
            if a_val > A_val[j]:
                total += (A_val[j])*A_key[j]
                a_val = a_val - A_val[j]
                A_val[j] = 0
            else:
                if i == j:

                    total += (A_val[j] - 1) * A_key[j]

                else:
                    total += (a_val)*A_key[j]
                A_val[j] = A_val[j]-a_val+1
                a_val = 0
            j +=1

print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby
from heapq import heapify, heappush, heappop

# sys.setrecursionlimit(5000)

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]
def linc(A, d=1): return map(lambda x: x + d, A)
def ldec(A, d=1): return map(lambda x: x - d, A)

N = n1()
A = nn()

A.sort(reverse=True)

tbl = [A[0], A[1]]
cft = A[0]

for i in range(2, N):
    c = 0
    for j in range(0, len(tbl)):
        tmp = min(tbl[j], tbl[(j+1)%len(tbl)])
        if tmp > c:
            c = tmp

    cft += c

print(cft)

Submission status: Wrong Answer

Solution code:
n=int(input())
frnds = list(map(int,input().split()))
frnds.sort(reverse=True)
cf = 0
circle =[]
for i in range(n):
    if i == 0:
        circle.append(frnds[i])
        continue
    elif i==1:
        cf += min(circle)
        circle.append(frnds[i])
    else:
        cf += min(circle)
        circle.append(frnds[i])
print(cf)

Submission status: Wrong Answer

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


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

A.reverse()

if N == 2:
    print(A[0])
    exit()

ans = 0
for i in range(N-2):
    if A[i] > A[i+1]:
        ans += A[i]
    else:
        ans += A[i+1]

ans += A[N-2]

print(ans)

Submission status: Wrong Answer

Solution code:

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

# 大きい順に並べ替え
a_list = sorted(a_list, reverse = True)

roop_list = [max(a_list)]

happy = 0

for i in range(0, n - 1):
    happy += min(roop_list)
    roop_list.append(a_list[i + 1])

print(happy)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache
from numba import jit

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n = I()
	a_list = LI()
	a_list.sort()
	ans = a_list[-1]
	if n % 2 == 0:
		for i in range(1,(n-2)//2+1):
			ans += a_list[-1-i]*2
	else:
		for i in range(1,(n-3)//2+1):
			ans += a_list[-1-i]*2
		ans += a_list[-1-(n-3)//2+1]
	print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import heapq
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    ans = A[-1]
    m = min(A.pop(), A.pop())
    target = [-1*m]
    heapq.heapify(target)
    while len(A) > 0:
        cur = -1 * heapq.heappop(target)
        ans += cur
        heapq.heappush(target, -1 * A.pop())
    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)

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

nums = []
nums = list(map(int, input().split()))
nums = sorted(nums, reverse=True)
cf = nums[0]

for i in range(2, n):
    nums_min = min(nums[i-1], nums[i-2])
    cf += nums_min

print(cf)

Submission status: Wrong Answer

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

A_sorted = sorted(A)
del A[0]

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

print(sum)

Submission status: Wrong Answer

Solution code:
N=int(input())

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

li.sort()
if N%2==0:
  print(sum(li[int(-N/2)-1:-1])+li[-1])
else:
  print(sum(li[-(N//2)-1:-1])+li[-1]+li[-(N//2)-1])

Submission status: Wrong Answer

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

ans = 0
a.sort(reverse=True)
ans += a[0]
ans += a[1]*(n-2)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N=int(input())
A=list(map(int,input().split()))
#多分下から2番目の値を取り続ける
A.sort()
#0 0
#1 並んでる数値で上から2番目に大きい数値
#2 並んでる数値で上から2番目に大きい数値
#3 並んでる数値で2番目に大きい数値
q=deque()
ans=0
for i in range(N):
    if i ==0:
        q.append(A[i])
    if i ==1:
        q.append(A[i])
        ans+=q[0]
    else:
        q.append(A[i])#新しい値を足す
        a=q.popleft()#でかい値を消す
        ans+=q[0]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

As.sort(reverse = True)

print(As)

circle_que = collections.deque()

circle_que.append(As[0])

ans = 0
for A in As[1:]:
    circle_que.append(A)
    circle_que.append(A)

    ans += circle_que.popleft()
    #print(ans)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
unconfortable = min(A)
print(sum(A) - unconfortable)

Submission status: Wrong Answer

Solution code:
import sys

import math
import itertools
import random
def next(index, lis):
    for i in range(index, 0):
        if (i != 0):
            return i

n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
isLeftSide = True
leftval=a[1]
rightval = a[1]
ans=a[0]
for i in range(2, n):
    if (isLeftSide):
        ans += leftval
        leftval = a[i]
        isLeftSide=False
    else:
        ans += rightval
        rightval = a[i]
        isLeftSide = True
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def mins(i):
  if i==len(b)-1:
    return min(b[0], b[i])
  else:
    return min(b[i], b[i+1])
              
if n==1:
  print(0)
elif n==2:
  print(a[0])
elif n>=3:
  confort = a[0] + min(a[0], a[1])
  b = [a[0], a[1], a[2]]
  for j in range(3, n):
    minlist = [mins(i) for i in range(len(b))]
    mx = max(minlist)
    confort += mx
    b.insert(b.index(mx), a[j])

  print(confort)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())), reverse = True)
B = [A[0]]
C = [A[0]]
ans = 0
for i in range(1, N):
  i0 = (C.index(max(C)) + 1) % i
  ans += max(C)
  i1 = (i0 + i - 1) % i
  B.insert(i0, A[i])
  C[i0] = min(B[i0], B[(i0+1) % (i+1)])
  C.insert(i1, min(B[i1], B[i0]))
print(ans)

Submission status: Wrong Answer

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

if n==2:
    print(a[0])
else:
    b=[a[1],a[2]]
    ans=a[0]+a[1]
    minlist=[min(b)]
    j=0
    for i in range(n-3):
        if j==0:
            j+=1
            ans+=b[0]
            b.append(a[i+2])
        else:
            j=0
            ans+=b[0]
            b=b[1:]
            b.append(a[i+2])
    print(ans)

Submission status: Wrong Answer

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

print(C[-2])