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:
  if N%2 == 0:
    cnt +=1
  while cnt<N:
    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 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(i, now_max)

print(-result)

Submission status: Wrong Answer

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

A = sorted(A, reverse=True)
ans = A[0]
if(N%2==0):
  ans += sum(A[1:int(len(A)/2)]*2)
else:
  ans += sum(A[1:int(len(A)/2)]*2) + A[int(len(A)/2)+1]
           
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
a.sort(reverse=True)
# print(a)
ans=0
for i in range(1,len(a)):
  ans+=a[i-1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a =[int(i) for i in input().split()]
a.sort(reverse=True)
s=0
c=0
l = []
f = 0
bf = -1
for i in a:
  if bf==i:
    l.append(i)
  else:
    l.append(i)
    l.append(i)
  bf=i

print(sum(l[1:n]))

Submission status: Wrong Answer

Solution code:
import heapq


def get_tuple(a, b):
    if a > b:
        a, b = b, a
    return -b-a, a


def main(a, N):
    a.sort(reverse=True)
    h = []
    if N == 1:
        comfort = 0
    else:
        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[0]))
            heapq.heappush(h, get_tuple(a[i], val[1]))
    print(comfort)


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

Submission status: Wrong Answer

Solution code:
import sys
from collections import namedtuple

class Inst:
  def __init__(self, value, next=None):
    self.value = value
    if next is None:
      self.next = self
    else:
      self.next = next
    
#Inst = namedtuple('Inst', ('value', 'next'))

length = int(sys.stdin.readline())

array = sorted([int(i) for i in sys.stdin.readline().split()], reverse=True)

root = Inst(value=array[0], next=None)

def iterate_all(root):
  yield root
  cur = root.next
  while cur != root:
    yield cur
    cur = cur.next

total_score = 0
for i, this in enumerate(array[1:]):
  best_node = root
  best_score = 0
  for node in iterate_all(root):
    score = min(node.value, node.next.value)
    if score > best_score:
      best_node = node
      best_score = score
  total_score += best_score
  
  best_node.next = Inst(value=this, next=best_node.next)

print(total_score, 182)

Submission status: Wrong Answer

Solution code:
import sys
from collections import namedtuple

class Inst:
  def __init__(self, value, next=None):
    self.value = value
    if next is None:
      self.next = self
    else:
      self.next = next
    
#Inst = namedtuple('Inst', ('value', 'next'))

length = int(sys.stdin.readline())

array = sorted([int(i) for i in sys.stdin.readline().split()], reverse=True)

root = Inst(value=array[0], next=None)

def iterate_all(root):
  yield root
  cur = root.next
  while cur != root:
    yield cur
    cur = cur.next

total_score = 0
for i, this in enumerate(array[1:]):
  best_node = root
  best_score = 0
  for node in iterate_all(root):
    score = min(node.value, node.next.value)
    if score > best_score:
      best_node = node
      best_score = score
  total_score += best_score
  
  best_node.next = Inst(value=this, next=best_node.next)
  
  print('---- iterating -----')
  for node in iterate_all(root):
    print(node.value)

print(total_score, 182)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    if n %2== 0:
        print(a[0]+sum(a[1:n//2])*2)
    else:
        print(a[0]+sum(a[1:n//2+1])*2)



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]
    ans_cnt = 0
    for i in range(N-1)[::-1]:
        ans += A[i]
        ans_cnt += 1
        if ans_cnt == N-2:
            break
        ans += A[i]
        ans_cnt += 1
        if ans_cnt == N-2:
            break
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = sorted(list(map(int, input().split())))
ans = 0
for i in range(N - 1):
    ans += A[N - math.ceil(i / 2) - 1]
    print(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
data = input().split()
man = [int(i) for i in data]
man.sort(reverse=True)
 
man2 = []
conf = 0
for i in range(N):
  man2.append(man[i])
  if len(man2) >= 2:
    conf += man[(i-1) % len(man2)]
  elif len(man2) >= 3:
  	conf += min(man[(i-1) % len(man2)],man[(i+1) % len(man2)])
  
print(conf)

Submission status: Wrong Answer

Solution code:
import heapq


def get_tuple(a, b):
    if a > b:
        a, b = b, a
    return -b, a


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


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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  5 22:49:34 2020

@author: Aruto Hosaka
"""


N = int(input())
A = list(map(int,input().split()))
A = sorted(A,reverse = True)
count = 0
count += A[0]
if N % 2 == 1:
    for n in range(1,(N+1)//2):
        count += 2*A[n]
else:
    for n in range(1,N//2):
        count += 2*A[n]
        count += A[N//2]
        
print(count)

Submission status: Wrong Answer

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

A.sort()
A.reverse()

list = []
ans = 0
list.append(A[0])
for i in range(len(A)):
        ans += list[i]
        list.append(A[i])
        list.append(A[i])

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
ans = a[0]
idx = 1
flag = False
for i in range(n-1):
    ans += a[idx]
    if flag:
        idx += 1
        flag = False
    else:
        flag = True
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  5 22:49:34 2020

@author: Aruto Hosaka
"""


N = int(input())
A = list(map(int,input().split()))
A = sorted(A,reverse = True)
count = 0
count += A[0]
if N % 2 == 1:
    for n in range(1,(N+1)//2):
        count += 2*A[n]
else:
    for n in range(1,N//2):
        count += 2*A[n]
        count += A[N//2]

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

N = int(input())

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

A_sort = sorted(A, reverse=True)
sum_num = A.pop(0)

i = 0
while True:
    num = A.pop(0)
    if i + 2 > N - 2:
        sum_num += num
        break
    else:
        sum_num += num * 2
        i += 2

print(sum_num)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  5 22:49:34 2020

@author: Aruto Hosaka
"""


N = int(input())
A = list(map(int,input().split()))
A = sorted(A,reverse = True)
count = 0
count += A[0]
if N % 2 == 1:
    for n in range(1,(N-1)//2):
        count += 2*A[n]
        count += A[N//2]
else:
    for n in range(1,N//2):
        count += 2*A[n]

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])
    ans = 0
    for i in range(1,n):
        p = -q.pop()
        ans += p
    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
b=sum(a[:-1])
if N>=3:
  if a[-2]!=a[-3]:
    b+=a[-3]-a[-2]
print(b)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
data = input().split()
man = [int(i) for i in data]
conf_max = max(man)
max_index = man.index(conf_max)
conf_min = min(man)
min_index = man.index(conf_min)

tmp = man[0]
man[0] = man[max_index]
man[max_index] = tmp

tmp = man[N-1]
man[N-1] = man[min_index]
man[min_index] = tmp

man2 = []
conf = 0
for i in range(N):
  man2.append(man[i])
  if len(man2) >= 2:
    conf += man[(i-1) % len(man2)]
  elif len(man2) >= 3:
  	conf += min(man[(i-1) % len(man2)],man[(i+1) % len(man2)])
  
print(conf)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

N = int(input())

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

A_sort = sorted(A, reverse=True)
sum_arr = [A.pop(0)]

i = 0
while True:
    num = A.pop(0)
    if i + 2 > N - 2:
        sum_arr += [num]
        break
    else:
        sum_arr += [num, num]
        i += 2

print(sum(sum_arr))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(sum(x)-min(x))

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:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
# 文字列の入力
N = int(input())
#開業されたN個要素を受け付ける
input_list = list(map(int, input().split()))

#print("test")

sorted_input = list(reversed(sorted(input_list)))

ling = []

ans = 0

for i in range(N):
    tmp = sorted_input.pop(0)
    if not (len(ling) < 3):
        max = 0
        max_point = -1
        for j in range(len(ling)-1):
            tmp_min = min(ling[j], ling[j+1])
            if tmp_min > max:
                max = tmp_min
                max_point = j
        tmp_min = min(ling[-1], ling[0])
        if tmp_min > max:
            ling.add(tmp)
            ans = ans + tmp_min
        else:
            ling.insert(max_point+1, max)
            ans = ans + max

    elif not (len(ling) != 0):
        ling.append(tmp)

    else:
        ans = ans + min(ling)
        ling.append(tmp)

    #print(ling)
    #print(ans)

print(ans)

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 = list(map(int,input().split()))
A_new = sorted(A, reverse=True)
A_feel = []
sum = 0
for i in range(N):
  if A_feel == [] or A_new[i] == A_new[0]:
    count = 1
  else:
    count = 2
  for j in range(count):
    A_feel.append(A_new[i])

for i in range(N-1):
  sum += A_feel[i]
  
print(sum)

Submission status: Wrong Answer

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

maxval = a[0]
cc = {maxval: 1}

ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
"""
    Satwik_Tiwari ;) .
    4th july , 2020  - Saturday
"""

#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase


import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#===============================================================================================
# code here ;))
def bs(a,l,h,x):
    while(l<h):
        # print(l,h)
        mid = (l+h)//2
        if(a[mid] == x):
            return mid
        if(a[mid] < x):
            l = mid+1
        else:
            h = mid
    return l

def sieve(a): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    for i in range(3,((10**6)+1),2):
        for j in range(i*i,((10**6)+1),i):
            a[j] = 0
    a[2] = 1 #special left case
    return (a)


def bfs(g,st):
    visited = [-1]*(len(g))
    visited[st] = 0
    queue = []
    queue.append(st)
    new = []
    while(len(queue) != 0):
        s = queue.pop()
        new.append(s)
        for i in g[s]:
            if(visited[i] == -1):
                visited[i] = visited[s]+1
                queue.append(i)
    return visited


def dfsusingstack(v,st):
    d = deque([])
    visited = [0]*(len(v))
    d.append(st)
    new = []
    visited[st] = 1
    while(len(d) != 0):
        curr = d.pop()
        new.append(curr)
        for i in v[curr]:
            if(visited[i] == 0):
                visited[i] = 1
                d.append(i)
    return new


def solve():
    n = int(inp())
    a = sorted(lis())
    print(sum(a[1:]))








testcase(1)
# testcase(int(inp()))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a.sort(reverse=True)
x = 1
cnt = 0
ans = 0
for ai in a:
    if cnt + x >= n-1:
        ans += ai * (n-cnt-1)
        break
    ans += ai * x
    cnt += x
    x *= 2

print(ans)

Submission status: Wrong Answer

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

A.sort(reverse= True)
ans = 0
best = 0
for i in range(N):
    if i == 0:
        continue
    elif i == 1:
        ans += A[0]
        best = A[1]
    else:
        ans += best
        best = A[i-1]
print(ans)

Submission status: Wrong Answer

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

A.sort(reverse=True)

if len(set(A)) >= 4:
    ans.append(A[0])
    A.pop(0)
    A.pop()
    for i in A:
        if len(ans) >= N-1:
            print(sum(ans))
            exit()
        ans.append(i)
        ans.append(i)
else:
    A.pop()
    print(sum(A))
    exit()

Submission status: Wrong Answer

Solution code:
n=int(input())
As = list(map(int, input().split()))
print(sum(As)-min(As))

Submission status: Wrong Answer

Solution code:

def main():
    N = int(input())
    conf = sorted((int(x) for x in input().split(" ")), reverse=True)
    result = []
    count = 0
    for i, x in enumerate(conf):
        if i == 0:
            result.append(x)
            continue
        if i % 2 == 0:
            result.append(x)
            count += min(result[-2], result[0])
        else:
            result.insert(0, x)
            count += min(result[-1], result[1])
    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	al.sort(reverse = True)
	rl = al[1]
	ll = al[1]
	ret = al[0]
	for v in al[2:]:
		if rl >= ll:
			ret += rl
			rl = v
		else:
			ret += ll
			ll  = v
	return ret
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys


def resolve():
    readline = sys.stdin.readline    # 1行だけ文字列にする

    N = int(readline())
    A = [int(x) for x in readline().split()]
    print(sum(A) - min(A))
    

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

input = sys.stdin.readline

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

inf = float('inf')
mod = 1000000007

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

class Queue:
    def __init__(self, queue = None):
        if type(queue) is type([]):
            self.queue = queue
        else:
            self.queue = []

    def enqueue(self, e):
        self.queue.append(e)
        return self.queue

    def dequeue(self):
        try:
            qEl = self.queue[0]
            del self.queue[0]
            return qEl
        except IndexError:
            return None


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

	A.sort()
	A = A[::-1]
	ans = 0
	maxs = 0
	cnt = 0
	fst = True

	ansans = []
	pgt = Queue()
	for i,val in enumerate(A):
		if i == 0:
			pgt.enqueue(val)
		else:
			tmp = pgt.dequeue()
			ansans.append(tmp)

			pgt.enqueue(val)

			if tmp == val:
				pgt.enqueue(val)
			else:
				pgt.enqueue(val)

	print(ansans)
	print(sum(ansans))


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

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()
    if N ==2:
        print(A[-1])
        return

    print(sum(A)-A[0]-A[1]+A[-2])

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
numlist = sorted(deque(map(int,input().split())))
ans = 0
max = [numlist.pop(),1]
for i in range(n-1):
    num = numlist.pop()
    if num == max[0]:
        ans += max[0]
        max[1] += 1
    else:
        ans += max[0]
        max[1] -= 1
        if max[1] == 0:
            max[0] = num;max[1] = i+2
print(ans)

Submission status: Wrong Answer

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

A = sorted(A, reverse=True)
ans = A[0]

ans += sum(A[1:len(A)-2]*2)
           
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import collections
col= collections.Counter(A)

setA = set(A)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

a_sorted = sorted(a, reverse=True)

if n % 2 == 0:
    print(a_sorted[0] + sum(a_sorted[1:n//2])*2)
else:
    print(a_sorted[0] + sum(a_sorted[1:n//2])*2 + a_sorted[n//2 + 1])

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush
N = int(input())
A = sorted(map(int, input().split()))
q = []
a = A.pop()
b = A.pop()
ans = a
heappush(q,(b, a, b))
heappush(q,(b, a, b))
while A:
    c = A.pop()
    m,a,b = heappop(q)
    ans += m
    heappush(q,(min(a, c), a, c))
    heappush(q,(min(b, c), c, b))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = input().split()
K = [int(n) for n in L]
print(sum(K)-min(K))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
k = N - 2
a = A.pop()
ans = a
n = k // 2
m = k - 2*n
B = A[N-1-n:]
C = A[N-1-n+m:]
ans += sum(B) + sum(C)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    else:
        ans += max[0]
        max[1] -= 1
        if max[1] == 0:
            max[0] = num;max[1] = 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
S = list(map(int,input().split()))
 
max=S[0];
 
semimax=S[1];
 
val=max;
 
for i in range(int(N)-2):
	val+=semimax
	if S[i+1]>max:
		max=S[i+1]
		if S[i+1]>semimax:
			semimax=S[i+1]

print(val)

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)