Skip to content

Instantly share code, notes, and snippets.

@uni745e
Created July 17, 2018 14:48
Show Gist options
  • Save uni745e/71516956f40a5e51ca4c0c6977a8da4b to your computer and use it in GitHub Desktop.
Save uni745e/71516956f40a5e51ca4c0c6977a8da4b to your computer and use it in GitHub Desktop.
AtCoder agc001
n = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(0,2*n,2):
ans += min(L[i], L[i+1])
print(ans)
#coding:utf-8
n, x = map(int, input().split())
def func(a, b):
if a < b:
if b%a == 0:
return (b//a*2 - 1)*a
else:
q, mod = divmod(b,a)
return 2*q*a + func(a, mod)
# return 2*a + func(a, b-a)
elif a > b:
if a%b == 0:
return (a//b*2 - 1)*b
else:
q, mod = divmod(a,b)#divmod : 商と余りを同時に取得できる
return 2*q*b + func(mod, b)
# return 2*b + func(a-b, b)#再帰回数が10000を超えるとエラー(20000000001, 4)など
else:
return a
if x == n/2:
print(3*x)
else:
print(x+(n-x)+func(x,n-x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment