input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
N = int(eval(input())) ans = '' if N == 0: print((0)) exit() while N != 0 and N != 1: if N > 0: if N%2: ans += '1' N = -(N//2) else: ans += '0' N = -N//2 else: if -N%2: ans += '1' N = -(N-...
N = int(eval(input())) if N == 0: print((0)) exit() ans = '' while N != 0: if N % 2: ans += '1' N -= 1 else: ans += '0' N //= -2 print((ans[::-1]))
p03286
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 n = int(readline()) if n == 0: print((0)) else: ans = [] while n: if n % -2 == 0: ans.append("0") n //= -2 else: ...
import sys def solve(): input = sys.stdin.readline mod = 10 ** 9 + 7 n = int(input().rstrip('\n')) bl = [] while True: if n == 0: break else: bl.append(str(n & 1)) n //= 2 n *= -1 bl.reverse() print(("".join(bl...
p03286
N = int(eval(input())) if N == 0: print((0)) exit() ans = '' while N != 0: if N%2: N -= 1 ans += '1' else: ans += '0' N //= -2 print((ans[::-1]))
N = int(eval(input())) if N == 0: print((0)) exit() ans = '' while N: if N%2: N -= 1 ans += '1' else: ans += '0' N //= -2 print((ans[::-1]))
p03286
# -*- coding: utf-8 -*- from bisect import bisect_left def inpl(): return list(map(int, input().split())) N = int(eval(input())) A = [] B = [] for i in range(2**16): A.append(int(("0{}"*16).format(*list(bin(i)[2:].zfill(16))), 2)) for i in range(2**16): B.append(-int(("{}0"*16).format(*list(bin(i)[2:...
from bisect import bisect_left def inpl(): return list(map(int, input().split())) N = int(eval(input())) U = [0]*32 L = [0]*32 U[0] = 1 for i in range(1, 32): if i%2: U[i] = U[i-1]*1 L[i] = L[i-1] + 2**i else: U[i] = U[i-1] + 2**i L[i] = L[i-1] * 1 searched = [0]...
p03286
a=int(eval(input()));s='' while a!=0:s+=str(a%2);a=-(a//2) print((int(s[::-1]) if s != '' else 0))
a=int(eval(input()));s='' while a!=0:s=str(a%2)+s;a=-(a//2) print((s if s != '' else 0))
p03286
from collections import deque S = deque() def main(): N = int(eval(input())) while N: if (abs(N % -2) == 1): S.appendleft('1') N -= 1 else: S.appendleft('0') N //= -2 if not S: S.append('0') print((''.join(list(...
def main(): N = int(eval(input())) S = "" if N == 0: print((0)) else: while N: if N % 2 != 0: S = '1' + S N -= 1 else: S = '0' + S N //= -2 print(S) return main(...
p03286
def main(): N = int(eval(input())) S = '' if N == 0: print((0)) else: while N: if N % 2 != 0: S = '1' + S N -= 1 else: S = '0' + S N //= -2 print(S) return main(...
def main(): N = int(eval(input())) S = "" if N == 0: print("0") else: while N: if N % 2: N -= 1 S = "1" + S else: S = "0" + S N //= -2 print(S) return main()
p03286
n=int(eval(input())) def isdig(n): if n>=0: digit=0 while n>2**digit: n-=2**digit digit+=2 else: digit=1 while n<-2**digit: n+=2**digit digit+=2 return digit x=["0"]*(isdig(n)+1) while n!=0: digit=isdig(n) if digit%2==0: n-=2**digit else: n+...
n=eval(input()) s=[] n=int(n) i=0 while n!=0: if n%2**(i+1)==0: s.append("0") else: s.append("1") n-=(-2)**i i+=1 s.reverse() if s==[]: s=["0"] print(("".join(s)))
p03286
# abc105c N = int(eval(input())) if N==0: print((0)) exit() a = "" b = -2 while N!=1: if N%b==0: a += "0" N = N//b else: a += "1" if N>0: N = N//b + 1 else: N = N//b + 1 if N==1: a += "1" print((a[::-1]))
import sys N = int(eval(input())) if N==0: print((0)) sys.exit() ans = "" b = -2 while N!=1: if N%b==0: ans += "0" N = N/b else: ans += "1" N = (N-1)/b ans += "1" print((ans[::-1]))
p03286
N = int(eval(input())) ans = "" while N != 0: if(N%2 == 0): ans += "0" else: ans += "1" N -= 1 N //= -2 if(ans == ""): ans = "0" print((ans[::-1]))
N = int(eval(input())) tmp = '' while N: if(N%2 == 0): tmp += '0' else: tmp += '1' N -= 1 N //= -2 if(tmp == ''): tmp = '0' print((tmp[::-1]))
p03286
def main(): n = int(eval(input())) ans = "" while n!=0: rem = n%(-2) n= n//(-2) if rem<0: rem = rem+2 n = n+1 ans = ans + chr(rem + ord('0')) if ans =="": print((0)) exit() print((ans[::-1])) if __name__ =="__main__": main()
# source wikipedia negabinary def main(): n = int(eval(input())) ans = "" while n!=0: rem = n%(-2) n= n//(-2) if rem<0: rem = rem+2 n = n+1 ans = ans + chr(rem + ord('0')) if ans =="": print((0)) exit() print((ans[::-1])) if __name__ =="__main__": main()
p03286
#import sys #input = sys.stdin.readline #template input import bisect def IT(): return int(eval(input())) def IL(): return [int(_) for _ in input().split()] def SL(): return [int(_) for _ in input().split()] def ILS(n): return [int(eval(input())) for _ in range(n)] def SLS(n): return ...
#import sys #input = sys.stdin.readline #template input import bisect def IT(): return int(eval(input())) def IL(): return [int(_) for _ in input().split()] def SL(): return [int(_) for _ in input().split()] def ILS(n): return [int(eval(input())) for _ in range(n)] def SLS(n): return ...
p03286
N=int(eval(input())) if(N==0): print((0)) exit() res='' while(N!=0): r=N%2 if(r<0): r+=2 res+=str(r) N=(N-r)//(-2) print((res[::-1]))
N=int(eval(input())) s='' if(N==0): print((0)) exit() while(N!=0): m=N%2 s+=str(m) N=(N-m)//-2 print((s[::-1]))
p03286
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] de...
# https://atcoder.jp/contests/arc026/tasks/arc026_2 import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdi...
p03286
# C - Base -2 Number n = int(eval(input())) s = "" while n!=0: s = str(n%2)+s n = -(n//2) print((0 if s=="" else s))
n=int(eval(input())) s='' while n!=0: s=str(n%2)+s n=-(n//2) if s!='': print(s) else: print((0))
p03286
n = int(eval(input())) ans = [] if n == 0: print('0') else: while n != 0: if n % -2 == -1: n = n // -2 + 1 ans.append('1') else: n = n // -2 ans.append('0') ans.reverse() print((''.join(ans)))
n = int(eval(input())) binary = [] if n == 0: print((0)) exit() while n != 0: if n % -2 != 0: binary.append('1') n //= -2 n += 1 else: binary.append('0') n //= -2 binary.reverse() print((''.join(binary)))
p03286
N = int(eval(input())) if N == 0: print((0)) exit() L = [] M = [] def bit_range(bit_length,maximum=0,minimal=0): for i in range(bit_length-1,-1,-1): if i % 2 == 0: maximum += pow(2,i) else: minimal += pow(-2,i) L.append(minimal) M.append(maximum...
N = int(eval(input())) if N == 0: print((0)) exit() L = [] M = [] for length in range(1,41): if length % 2 == 0: l = -2 * pow(4,length//2) // 3 m = (pow(4,length//2) - 1) // 3 elif length % 2 == 1: l = -2 * (pow(4,(length-1)//2) - 1) // 3 m = (pow(4,(lengt...
p03286
N = int(eval(input())) if N == 0: print((0)) exit() L = [] M = [] for length in range(1,41): if length % 2 == 0: l = -2 * pow(4,length//2) // 3 m = (pow(4,length//2) - 1) // 3 elif length % 2 == 1: l = -2 * (pow(4,(length-1)//2) - 1) // 3 m = (pow(4,(lengt...
N = int(eval(input())) ans = "" if N == 0: ans = "0" while N != 0: if N % 2 == 1: ans = "1" + ans else: ans = "0" + ans N //= 2 N *= -1 print(ans)
p03286
#!/usr/bin/env python n = int(eval(input())) if n == 0: print((0)) exit() ans = '' while abs(n) > 0: r = n%2 ans += str(r) n //= 2 n = -n if abs(n)%2 == 1: print(ans) else: print((ans[::-1]))
#!/usr/bin/env python n = int(eval(input())) if n == 0: print((0)) exit() ans = '' while abs(n) > 0: r = n%2 ans = str(r) + ans if r == 1: n -= 1 n //= (-2) print(ans)
p03286
N = int(eval(input())) A = list(map(int,input().split())) A.sort(reverse=True) # print(A) ans = A[0] for i in range(2,N): ans += A[i//2] print(ans)
def main(): import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int,input().split())) A.sort(reverse=True) ans = A[0] for i in range(2,N): ans += A[i//2] print(ans) if __name__ == '__main__': main()
p02615
n = int(eval(input())) a = list(map(int, input().split())) a.sort() if n%2: print((2*sum(a[n//2:])-a[-1]-a[n//2])) else: print((2*sum(a[n//2:])-a[-1]))
import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n = int(eval(input())) a = sorted(list(map(int, input().split()))) print((2*sum(a[n//2:])-a[-1]-(a[n//2] if n%2 else 0)))
p02615
import sys input = sys.stdin.readline from collections import * N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) l = [A[0]] for Ai in A[1:]: l.append(Ai) l.append(Ai) print((sum(l[:N-1])))
import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) l = [A[0]] for i in range(1, N): l.append(A[i]) l.append(A[i]) print((sum(l[:N-1])))
p02615
import itertools import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) ans = 0 for L in itertools.permutations(A): temp = 0 for i in range(1, N): temp += min(L[0], L[i-1]) ans = max(ans, temp) print(ans)
import itertools import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) ans = A[0] for i in range(2, N): ans += A[i//2] print(ans)
p02615
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) N = int(eval(input())) As = list(mapint()) As.sort(reverse=True) from heapq import heappush, heappop first = (As.pop(0)) hq = [] if N<2: print((0)) else: ...
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) N = int(eval(input())) As = list(mapint()) conf = 0 from heapq import heapify, heappop, heappush As.sort(reverse=True) m = As.pop(0) s = As.pop(0) conf += m Q = [...
p02615
# -*- coding: utf-8 -*- N = int(eval(input())) A = list(map(int,input().split())) A.sort(reverse=True) #print(A) ans = 0 list = [] for i in range(N): if ( i==0 ) : list.append(A[0]) else: max_index = list.index(max(list)) ans += list[max_index] list[max_index] = A[i] list.ins...
# -*- coding: utf-8 -*- N = int(eval(input())) A = list(map(int,input().split())) A.sort(reverse=True) #print(A) """ ans = 0 list = [] for i in range(N): if ( i==0 ) : list.append(A[0]) else: max_index = list.index(max(list)) ans += list[max_index] list[max_index] = A[i] lis...
p02615
N, *A = list(map(int, open(0).read().split())) A.sort(reverse=True) ans = 0 for i in range(N - 1): if i == 0: ans += A[i] else: ans += A[-(-i // 2)] print(ans)
N = int(eval(input())) X = list(map(int, input().split())) X.sort(reverse=True) ans = 0 cnt = 0 j = 0 for i in range(N): if i == 0: continue elif i == 1: ans += X[j] j += 1 else: ans += X[j] cnt += 1 if cnt == 2: j += 1 ...
p02615
#!/usr/bin/env python3 # encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math import sys import collections from decimal import Decimal # 10進数で考慮できる mod = 10**9+7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.de...
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) ans = 0 ans += A[0] tmp = 1 for i in range(1, N - 1): ans += A[tmp] if i % 2 == 0: tmp += 1 print(ans)
p02615
import heapq class ErasableHeapq: def __init__(self): self.p = list() self.q = list() self.len = 0 def insert(self, x): heapq.heappush(self.p, x) self.len += 1 return def erase(self, x): heapq.heappush(self.q, x) self.len -= 1...
def main(): N = int(eval(input())) A = list(map(int, input().split())) # 大きい順 A.sort() A = A[::-1] ans = 0 for i in range(1, N): ans += A[i // 2] print(ans) if __name__ == '__main__': main()
p02615
n = int(eval(input())) A = [int(x) for x in input().split()] A.sort(reverse=True) line = [A[0]] comfort = 0 for a in A[1:]: diff_comfort = [min(line[(i + 1) % len(line)], line[i]) for i in range(len(line))] pos = min(list(range(len(line))), key=lambda i: diff_comfort[i]) com...
n = int(eval(input())) A = [int(x) for x in input().split()] A.sort(reverse=True) print((A[0] + sum(A[1:(n - 2) // 2 + 1]) * 2 + (0 if n % 2 == 0 else A[(n - 1) // 2])))
p02615
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=False) #N = 12 #A = [12,9,9,6,6,5,5,4,3,2,1,1] ret = 0 array = [] array.append(A.pop()) while len(A) > 0: #print('array', array) comfort = [0 for i in range(len(array))] for i in range(len(comfort)): comfort[i]...
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=False) ret = 0 c_pointer = 0 comfort = [] tmp = A.pop() comfort.append(tmp) while len(A) > 0: tmp = A.pop() c_pointer += 1 comfort.append(tmp) comfort.append(tmp) print((sum(comfort[:c_pointer])))
p02615
n = int(eval(input())) a = list(map(int, input().split())) a = sorted(a, reverse=True) comfort = a[0:2] sum = max(a[0], a[1]) for j in a[2:]: key = 0 for i in range(len(comfort) - 1): comfort_value = min(comfort[1], comfort[-1]) comfort_value_kari = min(comfort[i], comfort[i + 1]) ...
import heapq n = int(eval(input())) arr = list(map(int, input().split())) arr = sorted(arr, reverse=True) ans = 0 q = [] heapq.heappush(q, -arr[0]) for i in range(1, n): tmp = heapq.heappop(q) tmp *= -1 ans += tmp heapq.heappush(q, -arr[i]) heapq.heappush(q, -arr[i]) print(ans)
p02615
import math n = int(eval(input())) f = list(map(int,input().split())) f.sort() ans = 0 for i in range(1,n): ans += f[n-math.floor(i/2)-1] print(ans)
n = int(eval(input())) f = list(map(int,input().split())) f.sort(reverse = True) ans = 0 if n%2 == 0: for i in range(n//2): ans += f[i] * 2 ans -= f[0] else: for i in range(n//2): ans += f[i] * 2 ans += f[n//2]-f[0] print(ans)
p02615
N=int(eval(input())) A=list(map(int,input().split())) A.sort(reverse=True) cnt=0 ans=[] ans.append(A[0]) ans.append(A[1]) cnt+=ans[0] for i in range(2,N): k=ans.index(A[int((i-1)/2)]) if k==len(ans)-1: kb=k-1 kn=0 else: kb=k-1 kn=k+1 if ans[kb]>=ans[kn...
N=int(eval(input())) A=list(map(int,input().split())) A.sort() A.insert(0,0) ans=0 for i in range(1,N): ans+=A[N-int(i/2)] print(ans)
p02615
n,*l=list(map(int,open(0).read().split())) from heapq import * l.sort() hq=[-l.pop()] heapify(hq) a=0 for _ in range(n-1): m=heappop(hq) a-=m t=-l.pop() heappush(hq,t) heappush(hq,t) print(a)
n,*l=list(map(int,open(0).read().split())) from heapq import * l.sort() q=[-l.pop()] a=0 for _ in range(n-1): m=heappop(q) a-=m t=-l.pop() heappush(q,t) heappush(q,t) print(a)
p02615
n,*l=list(map(int,open(0).read().split())) from heapq import * l.sort() q=[-l.pop()] a=0 for _ in range(n-1): m=heappop(q) a-=m t=-l.pop() heappush(q,t) heappush(q,t) print(a)
n,*l=list(map(int,open(0).read().split()));print((sum(sorted(l*2)[-2:~n:-1])))
p02615
n,*l=list(map(int,open(0).read().split()));print((sum(sorted(l*2)[-2:~n:-1])))
n,*l=list(map(int,open(0).read().split())) l.sort(reverse=1) print((sum(l[i//2] for i in range(1,n))))
p02615
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) ans = A[0] S = [A[0], A[1]] for i in range(2, len(A)): m = min(A[0], A[-1]) cnt = -1 for j in range(len(A)-1): if min(A[j], A[j+1]) > m: m = min(A[j], A[j+1]) cnt = j S = S[:cnt] +...
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) ans = A[0] N -= 2 for i in range(1, N): if N >= 2: ans += A[i]*2 N -= 2 elif N == 1: ans += A[i] N -= 1 else: break print(ans)
p02615
n = int(eval(input())) a = sorted(list(map(int, input().split())), reverse=True) sum_com = a[0] comfort = [a[1], a[1]] for ai in a[2:]: sum_com += comfort[0] if comfort[0] == ai: comfort.append(ai) else: comfort.pop(0) comfort += [ai, ai] print(sum_com)
n = int(eval(input())) a = sorted(list(map(int, input().split())), reverse=True) sum_com = 0 distinct_a = sorted(list(set(a)), reverse=True) comfort = {i: 0 for i in distinct_a} comfort[a[0]] = 1 max_com = 0 for ai in a[1:]: sum_com += distinct_a[max_com] if distinct_a[max_com] == ai: comfor...
p02615
def nth_element(array, will): will -= 1 n = len(array) left = 0 right = n-1 while right > left: i = left-1 j = right v = array[right] while True: i += 1 j -= 1 while array[i]<v:i+=1 while array[j]>v:j-=1 ...
# 入力 n = int(eval(input())) A = list(map(int,input().split())) A.sort() ans = 0 can = 1 # lastの数が後何回足されうるか will = n-1 # 次に足されるであろう数のindex for i in range(n-1): ans += A[will] can -= 1 if can == 0: # 足されきったら一つ小さい数へ can = 2 # 最大値以外は2回足されうる will -= 1 print(ans)
p02615
n = int(eval(input())) a = list(map(int,input().split())) sa = sorted(a,reverse=True) ans = 0 ls = [sa[0]] for v in sa[1:]: i = ls.index(max(ls)) ans+= ls[i] new_min = min(ls[i], v) ls = ls[:i] + [new_min, new_min] + ls[i+1:] #print(ls) print(ans)
n = int(eval(input())) a = list(map(int,input().split())) sa = sorted(a,reverse=True) ans = sa[0] i = 2 for v in sa[1:]: if i >= n: break #print("i:{} ans:{}".format(i,ans)) ans += v i += 1 if i >= n: break #print("i:{} ans:{}".format(i,ans)) ans += v i += 1 print(ans)
p02615
import itertools N = int(eval(input())) A = list(map(int, input().split())) conf_max = 0 for p in itertools.permutations(A): conf = 0 for i in range(1, N): conf += min(p[i-1], p[0]) if conf_max < conf: conf_max = conf print(conf_max)
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) conf_max = 0 for i in range(1, N): conf_max += A[i//2] print(conf_max)
p02615
import heapq n=int(eval(input())) arr=list(map(int,input().split())) arr=sorted(arr,reverse=True) ans=0 q=[] heapq.heappush(q,-arr[0]) for i in range(1,n): tmp=heapq.heappop(q) tmp*=-1 ans+=tmp heapq.heappush(q,-arr[i]) heapq.heappush(q,-arr[i]) print(ans)
n=int(eval(input())) arr=list(map(int,input().split())) arr=sorted(arr,reverse=True) ans=0 for i in range(1,n): ans+=arr[i//2] print(ans)
p02615
# coding: utf-8 from collections import deque def solve(*args: str) -> str: n = int(args[0]) A = sorted(map(int, args[1].split()), reverse=True) Q = deque() ret = 0 for i in range(-(-n//2)): if 0 < i: ret += min(Q[-1], Q[0]) if i % 2: Q.appe...
# coding: utf-8 def solve(*args: str) -> str: n = int(args[0]) A = sorted(map(int, args[1].split()), reverse=True) return str(sum([A[i//2] for i in range(1, n)])) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
p02615
n = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) cnt = n-1 i = 0 ans = 0 while cnt: if i == 0: cnt -= 1 ans += A[i] i += 1 else: if cnt < 2: ans += A[i]*cnt cnt = 0 else: ans += A[i]*2 ...
n = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) ans = 0 cnt = 0 for i, a in enumerate(A): if i == 0: ans += a cnt += 1 else: if n-1 - cnt >= 2: ans += a*2 cnt += 2 else: ans += a cnt ...
p02615
#D - Chat in a Circle N = int(eval(input())) A = list(map(int,input().split())) #ソート #B = [] arr = A.copy() left = 0 right = N -1 #B = sorted(A,reverse = True) def quicksort(arr,left,right): index = partition(arr,left,right) if left < index- 1 : quicksort(arr,left,index - 1) if index ...
#D - Chat in a Circle N = int(eval(input())) A = list(map(int,input().split())) #ソート arr = [] arr = sorted(A,reverse = True) Friend_min_max_wa = 0 i =0 j = 0 for i in range(N -1): if i % 2 != 0 : j = j + 1 Friend_min_max_wa = Friend_min_max_wa + arr[j] # 出力 print(Friend_min_max_wa)
p02615
from heapq import heapify, heappop, heappush N = int(eval(input())) A = list(map(int,input().split())) A.sort(reverse = True) #print(A) ans = A[0] Q = [(-A[1],-A[0]),(-A[1],-A[0])] #一つ目が大きいほうへ入れる heapify(Q) for i in range(2,N): nxt = A[i] s,t = heappop(Q) s *= -1; t*= -1 #正に戻す #print(s,ans) ans +...
N = int(eval(input())) A = list(map(int,input().split())) A.sort(reverse=True) B = [A[0]] for i in range(N-1): B.append(A[i+1]) B.append(A[i+1]) #print(B) ans = 0 for i in range(N-1): ans += B[i] print(ans)
p02615
from collections import deque n = int(eval(input())) a = sorted(map(int, input().split()), reverse=True) ans, cnt = 0, deque([a[0]]) for i in a[1:]: ans += cnt.popleft() cnt.extend([i,i]) print(ans)
n = int(eval(input())) a = sorted(map(int, input().split()), reverse=True) ans, que, cnt = 0, [a[0]], 0 for i in a[1:]: ans += que[cnt] que += [i, i] cnt += 1 print(ans)
p02615
import bisect import statistics n = int(eval(input())) a = list((int(x) for x in input().split())) a.sort() incl = [] score = 0 for i in range(len(a)): ain = a.pop() incl.append(ain) if i==0: continue if (len(incl)%2 == 1): score += statistics.median(incl) else: # s...
import bisect import statistics n = int(eval(input())) a = list((int(x) for x in input().split())) a.sort() incl = [] score = 0 for i in range(len(a)): ain = a.pop() incl.append(ain) if i==0: continue if (len(incl)%2 == 1): score += incl[ int(len(incl)/2) ] else: # ...
p02615
n = int(eval(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 def add(self, friend_val): if self.first_flag: self.queue_lst.append(friend_val) self.f...
n = int(eval(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(frien...
p02615
N = int(eval(input())) a = list(map(int, input().split())) a.sort(reverse = True) p=0 ppl = [a[0]]*2 best_index = 1 best_point = a[0] for i in a[1:]: p += best_point ppl = ppl[:best_index]+[i]+ppl[best_index:] #print(ppl) point_list = [min(ppl[i],ppl[i+1]) for i in range(0,len(ppl)-1)] #...
N = int(eval(input())) a = list(map(int, input().split())) a.sort(reverse = True) p = a[0] for i in range(N-2): #-1は上記a[0]分、もう-1は最初の要素挿入は加点されないため。 p += a[(i//2)+1] print(p)
p02615
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement from operator import itemgetter, mul from copy import deepcopy ...
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement from operator import itemgetter, mul from copy import deepcopy ...
p02615
#!/usr/bin/env python3 import sys from collections import deque class MM: def __init__(self, c_max, c_cnt): self.c_max = c_max self.c_cnt = c_cnt def solve(N: int, A: "List[int]"): sl = list(reversed(sorted(A))) score = 0 c_max = sl[0] h = {sl[0]: 1} queue = deque...
#!/usr/bin/env python3 import sys from collections import deque def solve(N: int, A: "List[int]"): sorted_list = list(reversed(sorted(A))) score = 0 queue = deque() queue.append(sorted_list[0]) cnt_map = {sorted_list[0]: 1} for i in range(1, len(sorted_list)): current_max = q...
p02615
N = int(eval(input())) A = [] a, *an = list(map(int, input().split())) A.append(a) A += an A.sort() Node = [] score = 0 Node.append(A.pop()) #print(A) for n in range(N - 1): score += Node[0] num = A.pop() Node = Node[1:] Node.append(num) Node.append(num) #print(Node) print...
N = int(eval(input())) A = [] a, *an = list(map(int, input().split())) A.append(a) A += an A.sort() Node = [] score = 0 Node.append(A.pop()) #print(A) start = 0 for n in range(N - 1): score += Node[start] num = A.pop() start += 1 #Node = Node[1:] Node.append(num) Node.ap...
p02615
n=int(eval(input())) a=list(map(int,input().split())) a.sort(reverse=True) d=[a[0]] ans=0 for i in range(1,n): tmp=max(d) ans=ans+tmp d.remove(tmp) d.append(a[i]) d.append(a[i]) print(ans)
n=int(eval(input())) a=list(map(int,input().split())) a.sort(reverse=True) ans=0 for i in range(1,n): ans=ans+a[i//2] print(ans)
p02615
from collections import deque N = int(eval(input())) K = list(sorted(map(int, input().split()), reverse=True)) max1 = K[0] max2 = K[1] if N == 2: print(max1) else: max3 = K[2] count = max1 + max2 cands = [(max1, max2), (max2, max3)] for k in K[3:]: max_cand = (0, 0) ma...
from collections import deque N = int(eval(input())) K = list(sorted(map(int, input().split()), reverse=True)) max1 = K[0] max2 = K[1] if N == 2: print(max1) else: max3 = K[2] count = max1 + max2 cands = deque([max2, max3, max3]) for k in K[3:]: cand = cands.popleft() ...
p02615
N = int(eval(input())) A = sorted([int(x) for x in input().split()], reverse=True) ans = 0 for i in range(N): if i == 0: B = [A[0]] continue index, mx = 0, 0 for j in range(len(B)): tmp = min(B[j-1], B[j]) if mx < tmp: mx = tmp index = ...
N = int(eval(input())) A = sorted([int(x) for x in input().split()], reverse=True) ans = 0 for i in range(N): if i == 0: continue else: ans += A[i//2] print(ans)
p02615
N=int(eval(input())) A=list(map(int,input().split())) B=sorted(A,reverse=True) ans=B[0] C=[B[0],B[1]] ans=B[0] for i in range(2,N): jmax=1 scoremax=min(C[0],C[1]) for j in range(1,len(C)-1): score = min(C[j],C[j+1]) if scoremax < score: scoremax = score ...
N=int(eval(input())) A=list(map(int,input().split())) B=sorted(A,reverse=True) ans=B[0] sheets=[B[0]] ans=0 for i in range(1,N): ans += sheets[i-1] sheets.append(B[i]) sheets.append(B[i]) print(ans)
p02615
import collections n=int(eval(input())) A=list(map(int,input().split())) A.sort(reverse=True) q=[] for i in range(n): if i==0: q.append(A[i]) else: q+=[A[i]]*2 print((sum(q[:n-1])))
n=int(eval(input())) A=list(map(int,input().split())) A.sort(reverse=True) q=[] for i in range(n): if i==0: q.append(A[i]) else: q+=[A[i]]*2 print((sum(q[:n-1])))
p02615
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse = True) Sum = 0 for i in range(len(A)): if i == 0: pass elif i == 1: Sum += A.pop(0) else: if i % 2 == 0: Sum += A[0] else: Sum += A.pop(0) print(Sum)
N = int(eval(input())) A = list(map(int, input().split())) A.sort() Sum = 0 for i in range(len(A)): if i == 0: pass elif i == 1: Sum += A.pop() else: if i % 2 == 0: temp = A.pop() Sum += temp else: Sum += temp print(Sum)
p02615
import sys from collections import deque input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) deq = deque([A[0]]) ans = 0 for x in A[1:]: ans += deq.popleft() deq.append(x) deq.append(x) print(ans)
import sys input = sys.stdin.readline N = int(eval(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)
p02615
n = int(eval(input())) a = list(map(int,input().split())) a.sort(reverse=True) ans = a[0] n -= 2 now = 1 while n > 0: if n >= 2: ans += a[now]*2 now += 1 n -= 2 elif n == 1: ans += a[now] n -= 1 now += 1 print(ans)
N = int(eval(input())) A = sorted(list(map(int,input().split())),reverse=True) ans = 0 for i in range(1,N): ans += A[i//2] print(ans)
p02615
n=int(eval(input())) a=sorted(list(map(int,input().split())),reverse=True) ans=0 for i in range(n-1): ans+=a[(i+1)//2] print(ans)
n=int(eval(input())) a=sorted(list(map(int,input().split())),reverse=1) b=0 for i in range(n-1): b+=a[(i+1)//2] print(b)
p02615
n = int(eval(input())) a = list(map(int, input().split())) a.sort() cnt = a.pop() tmp = a.pop() l = 0 for i in range(n - 2): if l == 2: l = 0 tmp = a.pop() cnt += tmp l += 1 print(cnt)
n = int(eval(input())) a = sorted(list(map(int, input().split())))[::-1] print((a[0] + sum(a[1:n // 2]) * 2 + sum(a[n // 2:n // 2 + n % 2])))
p02615
from collections import deque N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) a = deque(A) arrival = 1 ans = 0 while arrival < N: score = a.popleft() if arrival == 1: ans += score arrival += 1 else: ans += score*min(2, N - arriva...
N = int(eval(input())) a = list(map(int, input().split())) a.sort() arrival = 1 ans = 0 while arrival < N: score = a.pop() if arrival == 1: ans += score arrival += 1 else: ans += score*min(2, N - arrival) arrival += 2 print(ans)
p02615
N = int(eval(input())) A = list(map(int,input().split())) A.sort(reverse = True) circle = [A[0]] ans = 0 for i in range(1,N): max = 0 l = len(circle) for j in range(l): if max < min(circle[j],circle[(j+1)%l]): ins = j max = min(circle[j],circle[(j+1)%l]) c...
N = int(eval(input())) A = list(map(int,input().split())) A.sort(reverse = True) ans2 = A[0] cnt = 0 j = 1 for i in range(1,N-1): if cnt == 2: j += 1 cnt = 0 ans2 += A[j] cnt += 1 print(ans2)
p02615
# -*- coding: utf-8 -*- N = int(eval(input())) A = list(map(int, input().split())) a_sorted = sorted(A, key=lambda x: -x) circle = [a_sorted[0]] ans = 0 for a in a_sorted: tmp = 0 tmp_idx = -1 for i in range(len(circle) - 1): cand = min(circle[i], circle[i + 1]) if cand > tm...
# -*- coding: utf-8 -*- N = int(eval(input())) A = list(map(int, input().split())) a_sorted = sorted(A, key=lambda x: -x) circle = [a_sorted[0]] ans = 0 for idx, a in enumerate(a_sorted[1:]): ans += circle[idx] circle.extend([a, a]) print(ans)
p02615
n = int(eval(input())) friendly = [int(i) for i in input().split()] friendly.sort(reverse=True) place = [] place.append(friendly[0]) place=place*2 ans=0 for i in friendly[1:]: comfortable=[min(place[i], place[i+1]) for i in range(len(place)-1)] ans += max(comfortable) place.insert(comfortable.inde...
n = int(eval(input())) friendly = list(map(int, input().split())) friendly.sort(reverse=True) if len(friendly)<=2: print((sum(friendly[0:n-1]))) else: ans = friendly[0]+sum(friendly[1:(n+1)//2-1])*2+friendly[(n+1)//2-1]*((n+1)%2+1) print(ans)
p02615
N = int(eval(input())) alist = list(map(int, input().split())) alist.sort(reverse=True) sumscore=0 posit = list() posit.append(alist[0]) for n in range(1,N): sumscore = sumscore + posit[0] posit = posit[1:] posit.append(alist[n]) posit.append(alist[n]) print(sumscore)
N = int(eval(input())) alist = list(map(int, input().split())) alist.sort(reverse=True) sumscore=alist[0] for n in range(1,int(N/2)): sumscore = sumscore + alist[n]*2 if N%2==1: sumscore += alist[n+1] print(sumscore)
p02615
eval(input()) l = sorted(map(int, input().split(' '))) answer = 0 spots = [l.pop()] while l: n = l.pop() answer += spots[0] spots = spots[1:] + [n] * 2 print(answer)
eval(input()) l = sorted(map(int, input().split(' '))) answer = 0 spots = [l.pop()] x = len(l) for i in range(x): n = l.pop() answer += spots[i] spots.append(n) spots.append(n) print(answer)
p02615
def MergeSort(num_list): n = len(num_list) if len(num_list) == 1: return num_list #1. 整列されていないリストを2つのサブリストに分割する mid = int(round(n/2)) left = num_list[:mid] right = num_list[mid:] #2. 分割したリスト(サブリスト)を整列する。サブリストもマージソートを使って整列させる。(再帰関数) l = MergeSort(left) r = MergeSort(...
n = int(eval(input())) list =list(map(int, input().split())) list.sort(reverse=True) ans = 0 if n % 2 == 0: for i in range(n//2): ans += 2* list[i] ans -= list[0] else: for i in range((n-1)//2): ans += 2*list[i] ans += list[(n-1)//2] ans -= list[0] print(ans)
p02615
N = int(eval(input())) A = list(map(int,input().split())) A.sort(reverse=True) ans = 0 B = [] for a in A: if len(B)==0: ans += 0 B.append(a) elif len(B)==1: ans += B[0] B.append(a) else: max_ = min(B[0],B[-1]) idx = len(B)-1 for i in r...
N = int(eval(input())) A = list(map(int,input().split())) A.sort(reverse=True) ans = 0 idx = 0 cnt = 1 for a in range(N-1): ans += A[idx] cnt += 1 if cnt == 2: idx += 1 cnt = 0 print(ans)
p02615
n = int(eval(input())) lis = list(map(int, input().split())) lis = sorted(lis, reverse=True) ans = lis[0] t = 0 for i in range(1,n-1): if i % 2 != 0: t += 1 ans += lis[t] print(ans)
n = int(eval(input())) lis = list(map(int, input().split())) lis = sorted(lis, reverse=True) ans = 0 for i in range(1,n): ans += lis[i//2] print(ans)
p02615
from collections import deque def main(): eval(input()) # n friendliness = [int(x) for x in input().split()] friendliness.sort() friendliness = deque(friendliness) edges = deque() popped = friendliness.pop() edges.append(popped) ans = 0 while friendliness: ans...
from collections import deque def main(): n = int(eval(input())) # n friendliness = [int(x) for x in input().split()] friendliness.sort() friendliness = deque(friendliness) edges = deque() popped = friendliness.pop() edges.append(popped) ans = 0 counter = 0 while ...
p02615
from collections import deque def main(): eval(input()) # n friendliness = [int(x) for x in input().split()] friendliness.sort() friendliness = deque(friendliness) edges = deque() popped = friendliness.pop() edges.append(popped) ans = 0 while friendliness: ans...
from collections import deque def main(): eval(input()) # n friendliness = deque(sorted(int(x) for x in input().split())) edges = deque() popped = friendliness.pop() edges.append(popped) ans = 0 while friendliness: ans += edges.popleft() popped = friendliness.p...
p02615
from collections import deque def main(): eval(input()) # n friendliness = deque(sorted(int(x) for x in input().split())) edges = deque() popped = friendliness.pop() edges.append(popped) ans = 0 while friendliness: ans += edges.popleft() popped = friendliness.p...
from collections import deque def main(): eval(input()) # n friendliness = [int(x) for x in input().split()] friendliness.sort(reverse=True) edges = deque() edges.append(friendliness[0]) ans = 0 for fri in friendliness[1:]: ans += edges.popleft() edges.append(f...
p02615
from collections import deque def main(): eval(input()) (edges := deque()).append( (friendliness := deque(sorted(int(x) for x in input().split()))).pop()) ans = 0 while friendliness: ans += edges.popleft() edges.append(popped := friendliness.pop()) edges.appe...
from collections import deque def main(): eval(input()) # n friendliness = [int(x) for x in input().split()] friendliness.sort() friendliness = deque(friendliness) edges = deque() popped = friendliness.pop() edges.append(popped) ans = 0 while friendliness: a...
p02615
from collections import deque def main(): eval(input()) # n array = [int(x) for x in input().split()] array.sort() coming = deque(array) edges = deque() noob = coming.pop() edges.append(noob) ans = 0 while coming: ans += edges.popleft() noob = comin...
def main(): n = int(eval(input())) friendliness = [int(x) for x in input().split()] friendliness.sort(reverse=True) ans = 0 for i in range(1, n): ans += friendliness[i // 2] print(ans) if __name__ == '__main__': main()
p02615
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return eval(input()) def i(): return int(eval(input())) def S(): return input().split() def I(): return list(map(int,input().split())) def L(): return list(in...
N=int(eval(input())) l=sorted(list(map(int,input().split()))) l.reverse() s=l[0]+N%2*l[N//2] for i in range(N//2-1): s+=l[i+1]*2 print(s)
p02615
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) ans = 0 tmp = 0 for i in range(N): if i == 0: continue elif i == 1: ans += A.pop(0) elif i % 2 == 0: tmp = A.pop(0) ans += tmp else: ans += tmp print(ans)
N = int(eval(input())) A = list(map(int, input().split())) A.sort() ans = 0 tmp = 0 for i in range(N): if i == 0: continue elif i == 1: ans += A.pop() elif i % 2 == 0: tmp = A.pop() ans += tmp else: ans += tmp print(ans)
p02615
n = int(eval(input())) nums = [] nums = list(map(int, input().split())) nums = sorted(nums, reverse=True) cnt = 0 fir_num = nums[0] del nums[0] for i in range(n-2): fir_num += nums[0] cnt += 1 if cnt == 2: del nums[0] cnt = 0 print(fir_num)
n = int(eval(input())) nums = [] nums = list(map(int, input().split())) nums = sorted(nums, reverse=True) cnt = 0 fir_num = nums[0] del nums[0] for i in range(n-2): fir_num += nums[int(i/2)] print(fir_num)
p02615
# -*- coding: utf-8 -*- N = int(eval(input())) A = list(map(int, input().split())) A_sort = sorted(A, reverse=True) sum_num = A_sort.pop(0) i = 2 while i + 2 <= N: sum_num += A_sort.pop(0) * 2 i += 2 if i + 1 <= N: sum_num += A_sort.pop(0) print(sum_num)
# -*- coding: utf-8 -*- N = int(eval(input())) A = list(map(int, input().split())) A_sort = sorted(A) sum_num = A_sort.pop(-1) i = 2 while i + 2 <= N: sum_num += A_sort.pop(-1) * 2 i += 2 if i + 1 <= N: sum_num += A_sort.pop(-1) print(sum_num)
p02615
from collections import deque n = int(eval(input())) A = [*list(map(int, input().split()))] # print(n) # print(A) A.sort(reverse=True) # print(A) q = deque([A[0]]) B = [] for a in A[1:]: x = q.popleft() B.append(x) q.append(a) q.append(a) # print(q) # print(B) print((sum(B)))
from collections import deque eval(input()) A = [*list(map(int, input().split()))] A.sort(reverse=True) q = deque([A[0]]) P = [] for a in A[1:]: p = q.popleft() P.append(p) q.append(a); q.append(a) print((sum(P)))
p02615
from heapq import * n = int(eval(input())) A = [*[-int(x) for x in input().split()]] heapify(A) ans = -heappop(A) for c in range(0, n-2, 2): ans += -heappop(A) * (1<<(c+1 < n-2)) print(ans)
n = int(eval(input())) A = sorted([*list(map(int, input().split()))], reverse=True) ans = -A[0] for i in range(n): ans += A[i//2] print(ans)
p02615
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) ans = A[0] cur = 1 count = 1 while True: if count <= N - 3: ans += A[cur] * 2 count += 2 cur += 1 else: ans += A[cur] count += 1 if count == N - 1: break print(ans)...
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) ans = A[0] cur = 1 count = 1 while True: if count <= N - 3: ans += A[cur] * 2 count += 2 cur += 1 elif count == N - 2: ans += A[cur] count += 1 elif count == N - 1: ...
p02615
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def solve(): n = ni() a = sorted(nl...
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def solve(): n = ni() a = sorted(nl...
p02615
import sys from io import StringIO import unittest import os import heapq # 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む) sys.setrecursionlimit(999999999) # 実装を行う関数 def resolve(test_def_name=""): n = int(eval(input())) a_s = list(map(int, input().split())) a_s.sort(reverse=True) que = [] ...
import sys from io import StringIO import unittest import os import heapq # 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む) sys.setrecursionlimit(999999999) # 検索用タグ、優先度付きキュー、値の大きい物から取得 # 実装を行う関数 def resolve(test_def_name=""): n = int(eval(input())) a_s = list(map(int, input().split())) a_s.sort(r...
p02615
import sys sys.setrecursionlimit(10 ** 9) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MI1(): return list(map(int1, input().split())) def LI(): return list(map(int, input().split())) def LI1(): return...
import sys sys.setrecursionlimit(10 ** 9) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MI1(): return list(map(int1, input().split())) def LI(): return list(map(int, input().split())) def LI1(): return...
p02615
#!/usr/bin/env python3 import sys import collections def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): N = II() As = LI() As.sort() As.reverse() ...
#!/usr/bin/env python3 import sys import collections def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): N = II() As = LI() As.sort() As.reverse() ...
p02615
n = int(eval(input())) a = list(map(int, input().split())) a.sort() a.reverse() ans = 0 seq = [a[0]] seq.append(a[1]) ans += a[0] l = 2 for i in range(2, n): pos = 0 m_ans, M_ans = 0, 0 for p in range(l): np = p + 1 if np == l: np = 0 m, M = min(se...
n = int(eval(input())) a = list(map(int, input().split())) a.sort() a.reverse() #ans = 0 #seq = [a[0]] # #seq.append(a[1]) #ans += a[0] # #l = 2 #for i in range(2, n): # pos = 0 # m_ans, M_ans = 0, 0 # for p in range(l): # np = p + 1 # if np == l: # np = 0 # ...
p02615
n=int(eval(input())) a=list(map(int,input().split(' '))) def min_point(data): lgt = len(data) m=0 ins=0 for i in range(lgt): if i ==0: buf = min(data[i],data[lgt-1]) else: buf = min(data[i],data[i-1]) if buf > m: m=buf ...
n=int(eval(input())) a=list(map(int,input().split(' '))) a.sort(reverse=True) cnt=0 for i in range(1,n): if i==1: cnt+=a[0] else: j = (i // 2) cnt += a[j] print(cnt)
p02615
# -*- coding: utf-8 -*- N, = list(map(int, input().split())) A = list(map(int, input().split())) A = sorted(A)[::-1] ans = 0 for i, a in enumerate(A): if i==0: first = a elif i==1: ans += first pre = [A[1], A[1]] else: ans += pre[0] pre = pre[1:] ...
# -*- coding: utf-8 -*- N, = list(map(int, input().split())) A = list(map(int, input().split())) A = sorted(A)[::-1] ans = 0 for i, a in enumerate(A): if i==0: ans += a itr = 2 if itr >= N: break else: ans += a itr += 1 if itr >= N:...
p02615
N=int(eval(input())) A=list(map(int,input().split())) list.sort(A) l=[] n=A.pop() n2=A.pop() sum=n comfort={n2:[[n,n2],[n2,n]]} while A: max=sorted(comfort.keys())[-1] if comfort.get(max)==None:print((0)) n=comfort[max].pop() if comfort[max]==[]:del comfort[max] sum+=max n2=A.pop() if c...
eval(input()) A=list(map(int,input().split())) A.sort(reverse=True) B=[] ans=0 for i in A: if len(B)>=1: ans+=B[len(B)//2] B.append(i) print(ans)
p02615
n = int(eval(input())) a = list(map(int,input().split())) a.sort(reverse=True) cnt = a.pop(0) for i in range(n-2): if i % 2 == 0: cnt += a[0] else: cnt += a.pop(0) print(cnt)
n = int(eval(input())) a = list(map(int,input().split())) a.sort(reverse=True) cnt = a.pop(0) if (n-2) % 2 == 0: tmp = 2 * sum(a[0:(n-2)//2]) else: tmp = 2 * sum(a[0:(n-2)//2]) + a[(n-2)//2] cnt += tmp print(cnt)
p02615
conf = 0 num_char = int(eval(input())) char = list(map(int, input().split())) char.sort(reverse=True) count = 0 conf_int = 0 for i in range(num_char): if count == 0: count = 1 elif count == 1: count = 2 conf = char[conf_int] count_int = 0 conf_int = 1 else: if count_int == 0...
N = int(eval(input())) As = sorted(map(int, input().split()), reverse=True) score = As[0] counter = 0 index = 1 for i in range(2, N): score += As[index] if counter == 0: counter += 1 else: counter -= 1 index += 1 print(score)
p02615
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) cnt = 1 idx = 0 ans = 0 while cnt <= N-1: ans += A[idx] if cnt % 2 == 1: #ans += A[idx] idx += 1 #else: #ans += A[idx] cnt += 1 print(ans)
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) ans = A[0] #最大値だけ1回 for i in range(N-2): ans += A[i//2 + 1] print(ans)
p02615
import heapq N = int(eval(input())) A = list(map(int,input().split())) heap = [] for i in range(N): heapq.heappush(heap,-A[i]) if N==2: ans = -heapq.heappop(heap) elif N==3: ans = -heapq.heappop(heap)-heapq.heappop(heap) else: ans = 0 ans = -heapq.heappop(heap) if N%2==0: f...
N = int(eval(input())) A = sorted(list(map(int,input().split())),reverse=True) if N%2==0: cnt = A[0] for i in range(1,N//2): cnt += 2*A[i] print(cnt) else: cnt = A[0] for i in range(1,N//2): cnt += 2*A[i] cnt += A[N//2] print(cnt)
p02615
N = int(eval(input())) A = sorted(list(map(int,input().split())),reverse=True) if N%2==0: cnt = A[0] for i in range(1,N//2): cnt += 2*A[i] print(cnt) else: cnt = A[0] for i in range(1,N//2): cnt += 2*A[i] cnt += A[N//2] print(cnt)
N = int(eval(input())) A = sorted(list(map(int,input().split())),reverse=True) cnt = A[0] k = (N+1)//2-1 for i in range(1,1+k): cnt += 2*A[i] if N%2==1: cnt -= A[k] print(cnt)
p02615
import os import sys from io import BytesIO, IOBase # from collections import defaultdict as dd # from collections import deque as dq # import itertools as it # from math import sqrt, log, log2 # from fractions import Fraction import heapq def main(): n = int(eval(input())) nums = list(map(int, input...
n = int(eval(input())) friend = list(map(int, input().split())) friend.sort(reverse = True) ans = friend[0] i = 1 ind = 1 while i < n - 1: for j in range(2): ans += friend[ind] i += 1 if i == n-1: break ind += 1 print(ans)
p02615
N=int(eval(input())) A=list(map(int,input().split())) A.sort(reverse=True) ans=0 li=[A[0]] for i in range(1,N): ans+=li[0] li.pop(0) li.append(A[i]) li.append(A[i]) print(ans)
N=int(eval(input())) A=list(map(int,input().split())) A.sort(reverse=True) ans=0 li=[A[0]] for i in range(1,N): ans+=li[i-1] li.append(A[i]) li.append(A[i]) print(ans)
p02615
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) ans = sum(A[:N//2])*2-A[0] if N%2==1: ans += A[N//2] print(ans)
def solve(): N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) ans = A[0] cnt = 1 for i in range(1,N-1): ans += A[i] cnt += 1 if cnt==N-1: break ans += A[i] cnt += 1 if cnt==N-1: break return ans print((solve()))
p02615