Problem:


Score: 200 points

Problem Statement

We have N cards. A number a_i is written on the i-th card.

Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.

The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.

Constraints

N is an integer between 1 and 100 (inclusive).

a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:  

N
a_1 a_2 a_3 ... a_N

Output

Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.

Sample Input 1

2
3 1

Sample Output 1

2

First, Alice will take the card with 3. Then, Bob will take the card with 1.
The difference of their scores will be 3 - 1 = 2.

Sample Input 2

3
2 7 4

Sample Output 2

5

First, Alice will take the card with 7. Then, Bob will take the card with 4. Lastly, Alice will take the card with 2. The difference of their scores will be 7 - 4 + 2 = 5. The difference of their scores will be 3 - 1 = 2.

Sample Input 3

4
20 18 2 18

Sample Output 3

18



Sample input:
2
3 1


Sample output:
2

Submission status: Accepted

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

for i in range(1,N+1):
  if i%2==0:
    pick_bob=max(A)
    Bob+=pick_bob
    A.remove(pick_bob)
  else:
    pick_alice=max(A)
    Alice+=pick_alice
    A.remove(pick_alice)
    
print(Alice-Bob)

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    A=LIST()
    A=sorted(A,reverse=True)
    al=len(A)
    alice=0
    bob=0
    for i in range(al//2):
        alice+=A[2*i]
        bob+=A[2*i+1]
    if al%2==1:
        alice+=A[-1]
    print(alice-bob)    
if __name__ == '__main__':
    do()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

alice, bob = [],  []

card = sorted(card)
for i, _ in enumerate(range(n)):
    if i % 2 == 0:
        alice.append(card.pop())
    else:
        bob.append(card.pop())
        
print(sum(alice) - sum(bob))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]

a = sorted(a)
alice = 0
bob = 0
for i in range(n):
    if i % 2 == 0:
        alice += a[i]
    else:
        bob += a[i]

print(abs(alice - bob))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
AS = list(map(int,input().split()))
AS.sort()
AS.reverse()
print(sum(AS[::2]) - sum(AS[1::2]))

Submission status: Accepted

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

points = [0,0]#alice,bob
i = 0
while AS:
  point = max(AS)
  points[i] += point
  AS.remove(point)
  i = 1-i
print(points[0]-points[1])

Submission status: Accepted

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

a.sort()
a.reverse()

t = 'A'
alice = []
bob = []
while(True):
    if t == 'A':
        t = 'B'
        x = a.pop(0)
        alice.append(x)
    elif t == 'B':
        t = 'A'
        x = a.pop(0)
        bob.append(x)

    if len(a) == 0:
        break

print(sum(alice)-sum(bob))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
print(abs(sum(a[0::2]) - sum(a[1::2])))

Submission status: Accepted

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

a = 0
b = 0

for i in range(len(list)):
  if i % 2 == 0:
    a += list[i]
  else:
    b += list[i]

print(a - b)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a1 = sorted(a)
sum_a = 0
sum_b = 0

for i in range(n):
    if(n%2==0):
        if(i%2 != 0):
            sum_a += a1[i]
        else:
            sum_b += a1[i]
    else:
        if(i%2 == 0):
            sum_a += a1[i]
        else:
            sum_b += a1[i]
print(sum_a-sum_b)

Submission status: Accepted

Solution code:
from functools import reduce 
from operator import add
 
n = int(input())
arr = list(map(int, input().split()))
 
pt_a = 0
pt_b = 0
 
arr.sort(reverse=True)
 
for ind, num in enumerate(arr):
  if ind % 2 == 0:
    pt_a += num
  else:
    pt_b += num
 
print(pt_a - pt_b)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main(n, a):
    a.sort()
    ans = 0

    for i in range(n):
        if i % 2 == 0:
            ans += a.pop()
        else:
            ans -= a.pop()

    print(ans)


if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    main(n, a)

Submission status: Accepted

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

alice_sum = 0
bob_sum = 0

while len(an_list) != 0:
    alice_sum += max(an_list)
    an_list.remove(max(an_list))
    if len(an_list) != 0:
        bob_sum += max(an_list)
        an_list.remove(max(an_list))

print(alice_sum - bob_sum)

Submission status: Accepted

Solution code:
N = int(input())

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

sum_alice = 0
sum_bob = 0
a = sorted(a, reverse=True)

for i in range(len(a)):
    if i % 2 == 0:
        sum_alice += a[i]
    else:
        sum_bob += a[i]

print(sum_alice - sum_bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
list= list(map(int, input().split()))
alice=[]
bob=[]
list.sort(reverse=True)
for i in range(N):
    if i%2==0:
        alice.append(list[i])
    else:
        bob.append(list[i])
print(sum(alice)-sum(bob))

Submission status: Accepted

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



print(sum(lists[::2])-sum(lists[1::2]))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
print(sum(A[0::2])-sum(A[1::2]))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
A=0
B=0
a_new = sorted(a)
for i in range (N):
	if N%2 == 0:
		if i%2 == 0:
			B += a_new[i]
		else:
			A += a_new[i]
	else:
		if i%2 == 1:
			B += a_new[i]
		else:
			A += a_new[i]
print(A-B)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
L = 0

for i in range(len(A)):
     L += ((-1)**i)*A[i]

print(L)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
alice=0
bob=0
a=list(map(int,input().split()))
a.sort(reverse=True)
for i in range(N):
    if(i%2==0):
        alice=alice+a[i]
    else:
        bob=bob+a[i]
print(abs(alice-bob))

Submission status: Accepted

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

sort_a_list = sorted(a_list, reverse=True)

alice = 0
bob = 0

for i, a in enumerate(sort_a_list):
    if i % 2 == 0:
        alice += a
    else:
        bob += a

print(alice - bob)

Submission status: Accepted

Solution code:
import math

#n, a, b= map(int, input().split())
#a, b  = map(int, input().split())
#h = list(map(int, input().split()))
#s = list(str(input()))
n = int(input())
a = list(map(int, input().split()))

alice = 0
bob   = 0

for i in range(n):
  a.sort(reverse=True)
  alice = alice + a[0]*((i+1)%2)
  bob   = bob   + a[0]*(i%2)
  a[0] = 0
    
print(alice - bob)

Submission status: Accepted

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

A.sort(reverse=True)
print(sum(A[0::2]) - sum(A[1::2]))

Submission status: Accepted

Solution code:
import numpy as np

def solve(n, A):
    res = 0
    while A:
        i = np.argmax(A)
        res += A[i] if (len(A) + n) % 2 == 0 else -A[i]
        A.pop(i)
    return res

_n = int(input())
_A = list(map(int, input().split()))
print(solve(_n, _A))

Submission status: Accepted

Solution code:
N = int(input())
a = sorted([int(x) for x in input().split()], reverse=True)

print(sum(a[0::2])-sum(a[1::2]))

Submission status: Accepted

Solution code:
N = int(input())
a = sorted([int(x) for x in input().split()], reverse=True)

alice = sum(a[0::2])
bob = sum(a[1::2])
print(alice-bob)

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

A = int(readline())
S = [int(i) for i in readline().decode().split()]
S.sort()
S.reverse()

ans = 0
j = 1
for i in S:
    ans += i * j
    j *= -1
print(ans)

Submission status: Accepted

Solution code:
input()
a = sorted(map(int, input().split()))[::-1]
print(sum(a[::2]) - sum(a[1::2]))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
x = []
y = []
for i, v in enumerate(sorted(a, reverse=True)):
    if (i + 1) % 2 != 0:
        x.append(v)
    else:
        y.append(v)
print(sum(x) - sum(y))

Submission status: Accepted

Solution code:
n=input()

a=sorted(map(int,input().split()))[::-1]

print(sum(a[::2])-sum(a[1::2]))

Submission status: Accepted

Solution code:
N = int(input())
alist = sorted(list(map(int, input().split())))[::-1]
a = sum(alist[::2])
b = sum(alist[1::2])
print(a - b)

Submission status: Accepted

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

def main():
  n = int(input())
  a = list(map(int, input().strip().split()))
  a.sort(reverse=True)
  alice, bob = 0, 0
  for i in range(n):
    if i % 2 == 0:
      alice += a[i]
    else:
      bob += a[i]
  print(alice-bob)
    
    

if __name__=="__main__":
  main()

Submission status: Accepted

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

#整数値入力 1文字の入力
def input_one_number():
    return int(input())

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

#整数値龍力　複数の入力(配列)
def input_multiple_number_as_list():
    return list(map(int, input().split()))

#2次元配列入力
def input_map():
    return [list(map(int,list(input()))) for i in range(h)]

#リスト出力
def print_list(list):
    print(*list)
    return

#2次元配列出力
def print_map(maplist):
    for i in maplist:print(*i, sep='')
    return

#素数生成
def generate_primenums():
    n = 100
    primes = set(range(2, n+1))
    for i in range(2, int(n**0.5+1)):
        primes.difference_update(range(i*2, n+1, i))
    primes=list(primes)
    return primes

def memo():
    a=[0]*5
    b=a  #良くない配列のコピー
    b2=a[:]  #1次元のときはコピーはこれで良い
    a[1]=3
    print('b:{}, b2:{}'.format(b,b2))  #b:[0, 3, 0, 0, 0], b2:[0, 0, 0, 0, 0]
    
    import copy
    a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
    b=copy.deepcopy(a)  #2次元配列はこうコピーする
    
    #内包表記奇数のみ
    odd=[i for i in range(100) if i%2==1] #[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]

    #二部探索
    import bisect
    a = [1, 2, 3, 5, 6, 7, 8, 9]
    b=bisect.bisect_left(a, 8)

    #combinations、組み合わせ、順列
    from itertools import permutations, combinations,combinations_with_replacement,product
    a=['a','b','C']
    print(list(permutations(a)))
    print(list(combinations(a,2)))
    print(list(combinations_with_replacement(a,3)))


#階乗
def kaijo(n):
    import math
    return math.factorial(n)

#選び方（コンビネーション nCr）
def num_combination(n,r):
    import math
    return math.factorial(n) // math.factorial(n - r)


#最大公約数、最小公倍数
def calc_gcd(a,b):
    import fractions
    GCD=fractions.gcd(a,b)
    lcm=a*b//gcd
    return gcd,lcm

#複数の最大公約数
def calc_gcd_list(l):
    gcd = l[0]
    for i in range(1, N):
        gcd = fractions.gcd(gcd, l[i])
    return gcd

#各桁の和
def sum_digit(n):
    sum = 0
    while n > 0:
        sum += n%10
        n //= 10
    return sum

N = input_one_number()
lst_a = input_multiple_number_as_list()

lst_a.sort(reverse=True)

alice = 0
bob = 0

if len(lst_a) %2 == 1:
    lst_a.append(0)

for i in range(len(lst_a)//2):
    alice += lst_a[i*2]
    bob += lst_a[i*2+1]

print(alice-bob)

Submission status: Accepted

Solution code:
def getInput():
    return [int(i) for i in input().rstrip().split(' ')]

N = getInput()[0];
a_i = getInput()
a_i.sort(reverse=True)
ret = 0

for i in range(1, N+1):
    if not i % 2 == 0:
        ret += a_i.pop(0)
    else:
        ret -= a_i.pop(0)
print(ret)

Submission status: Accepted

Solution code:
def getInput():
    return [int(i) for i in input().rstrip().split(' ')]

N = getInput()[0];
a_i = getInput()
ret = 0

for i in range(1, N+1):
    if not i % 2 == 0:
        ret += a_i.pop(a_i.index(max(a_i)))
    else:
        ret -= a_i.pop(a_i.index(max(a_i)))
print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
Alice = []
Bob = []
for i in range (N):
  if i % 2 == 0:
    Alice.append(a[i])
  else:
    Bob.append(a[i])
print(sum(Alice)-sum(Bob))

Submission status: Accepted

Solution code:
N = int(input())
lst = list(map(int, input().split()))
lst.sort(reverse = True)
A = 0
B = 0


for i in range(N):
    if i%2 == 0:
        A += lst[i]
    else:
        B += lst[i]

print(A - B)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
n = np.array(list(map(int, input().split())))
n_sort = np.sort(n)[::-1]
alice=0
bob=0

#print(np.sort(n)[::-1])
#print(len(n))

for i in range(len(n_sort)) :
  if i % 2 == 0 :
    alice = alice + n_sort[i]
  else :
    bob = bob + n_sort[i]

#print(alice)
#print(bob)
print(alice - bob)

Submission status: Accepted

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

a.sort(reverse=True)
alice_score = sum(a[0::2])
bob_score = sum(a[1::2])

print(alice_score - bob_score)

Submission status: Accepted

Solution code:
# coding: utf-8
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
a=0
b=0
for i in range(N):
    if i%2==0:
        a+=A[i]
    else:
        b+=A[i]
print(a-b)

Submission status: Accepted

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

alice = 0
bob = 0
for i in range(n):
    if i % 2 == 0:
        alice += a[i]
    else:
        bob += a[i]
print(alice - bob)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
N = int(input())
# スペース区切りの整数の入力
line = list(map(int, input().split()))
a = b = 0

for i in range(N):
    n = max(line)
    line.remove(n)
    if i % 2:
        b += n
    else:
        a += n
        
print(a-b)

Submission status: Accepted

Solution code:
n = int(input())
cardList = map(int,input().split())
cl = list(cardList)
cl.sort(reverse=True)
alice = 0
bob = 0
turn = True
for c in cl:  
  if turn:
    alice+= c
    turn = False
  else:
    bob +=c
    turn =True
    
print(alice-bob)

Submission status: Accepted

Solution code:
#python3
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort(reverse=True)
    print(sum([a[i] for i in range(n) if i%2 == 0]) - sum([a[i] for i in range(n) if i%2 !=0]))
main()

Submission status: Accepted

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

Submission status: Accepted

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

alice = 0
bob = 0

for i in range(N):
    if i % 2 == 0:
        alice += A[i]
    else:
        bob += A[i]

print(alice - bob)

Submission status: Accepted

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

# 並び替える
a = sorted(a, reverse=True)

alice = sum(a[0::2])
bob = sum(a[1::2])


if alice > bob:
    print(alice - bob)
else:
    print(bob-alice)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
print(sum(a[::2])-sum(a[1::2]))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
print(sum(a[::2])-sum(a[1::2]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
l=sorted(list(map(int,input().split())))[::-1]
print(sum(l[::2])-sum(l[1::2]))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a = sorted(a)[::-1]
alice = 0
bob = 0
for i in range(N):
  if i % 2 == 0:
    alice += a[i]
  else:
    bob += a[i]
    
print(alice - bob)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
alice = 0
bob = 0
a = sorted(a, key= lambda x: -x)

for i in range(len(a)):
  if i % 2 == 0:
    alice += a[i]
  else:
    bob += a[i]
print(alice - bob)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
print(sum(a[0::2]) - sum(a[1::2]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [ int(a) for a in input().split() ] # [45, 21, 30, 45]
A_sort = sorted(A) # [21, 30, 45, 45]
A_sort.sort(reverse=True) # [45, 45, 30, 21]
sum_alice = 0
sum_bob = 0
for i in range(0,N):
  if i%2 == 0:
    sum_alice += A_sort[i]
  else:
    sum_bob += A_sort[i]
print(sum_alice - sum_bob)

Submission status: Accepted

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

alice = []
bob = []

for i in range(1, n+1):
    if i%2!=0:
        alice.append(a.pop(a.index(max(a))))
    else:
        bob.append(a.pop(a.index(max(a))))

print(sum(alice) - sum(bob))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
"""AtCoder Beginner Contest 088: B - Card Game for Two
https://atcoder.jp/contests/abc086/tasks/abc088_b
"""

__author__ = 'bugttle <bugttle@gmail.com>'


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

    answer = 0
    an.sort(reverse=True)
    for i in range(N):
        if i % 2 == 0:
            answer += an[i]
        else:
            answer -= an[i]

    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

a_s = sorted(al, reverse=True)

ali = 0
bob = 0
count = 0

for a in a_s:
    count += 1
    if count %2 != 0:
        ali += a
    else:
        bob += a

print(ali-bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ab = [x for x in a[1::2]]
ba = [x for x in a[0::2]]
print(abs(sum(ab)-sum(ba)))

Submission status: Accepted

Solution code:
n = int(input())
ais = input().split()
ais_int = [int(a) for a in ais]
ais_sort = ais_int.sort()
alice = 0
bob = 0
if n % 2 == 0:
  for i in range(n):
    if i % 2 == 1:
      alice += int(ais_int[i])
    else:
      bob += int(ais_int[i])
else:
  for j in range(n):
    if j % 2 == 0:
      alice += int(ais_int[j])
    else:
      bob += int(ais_int[j])
print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

point = 0

lista.sort()

for _ in range((n + 1) // 2):
  point += lista.pop()
  if lista == []:
    break
  else:
    point -= lista.pop()
    
print(point)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
a = sorted(a, reverse=True)
ans = 0
for n in range(0,N,2):
    ans += a[n]
    if n+1 < N:
        ans -= a[n+1]
print(ans)

Submission status: Accepted

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

a.sort(reverse=True)
Alice = 0
Bob = 0
for i in range(len(a)):
    if i%2==0:
        Alice+=a[i]
    else:
        Bob+=a[i]

diff = Alice - Bob
print(diff)

Submission status: Accepted

Solution code:


import numpy as np

input()
#a=sorted(list(map(int,input().split())),reverse=True)
a=sorted(map(int,input().split()),reverse=True)
#print(a)
ans=sum(a[::2])-sum(a[1::2])
print(ans)

Submission status: Accepted

Solution code:
import sys

if __name__ == "__main__":
    args = sys.stdin.read().split()
    N, A = int(args[0]), list(map(int, args[1:]))  # N = len(A)
    A.sort(reverse=True)

    alice = sum(A[0::2])
    bob = sum(A[1::2])
    print(alice - bob)

Submission status: Accepted

Solution code:
n = int(input())
l = [int(i) for i in input().split()]

nl = sorted(l, reverse=True)

a = 0
b = 0

for i in range(n):
  if i % 2 == 0:
    a += nl[i]
  else:
    b += nl[i]
    
print(a - b)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
alice=0
bob=0
for i,item in enumerate(a):
  if i%2==0:
    alice+=item
  else:
    bob+=item
print(alice-bob)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = [int(i) for i in input().split()]

a.sort()
alice = 0
bob = 0
if n % 2 == 0:
    for i in range(n):
        if i % 2 == 0:
            bob += a[i]
        else:
            alice += a[i]
else:
    for i in range(n):
        if i % 2 == 0:
            alice += a[i]
        else:
            bob += a[i]

print(alice - bob)

Submission status: Accepted

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

x=0
y=0
for i in range(n):
  if i%2==0:
    x+=a[i]
  else:
    y+=a[i]
print(x-y)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
scores = list(int(i) for i in input().split())

sorted_scores = sorted(scores)[::-1]
alice = sum(sorted_scores[::2])
bob = sum(sorted_scores[1::2])

print(alice - bob)

Submission status: Accepted

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

sorted_a = sorted(a, reverse=True)

alice = 0
bob = 0
for i in range (N):
    #Aliceのターン
    if i % 2 == 0:
        alice += sorted_a[i]
    else:
        bob += sorted_a[i]

print(alice-bob)

Submission status: Accepted

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

print(sum(points[::2]) - sum(points[1::2]))

Submission status: Accepted

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

# 最適な戦略：Aliceは大きな数字から取っていく
Alice = []
Bob = []
for i in range((N + 1) // 2):
  # Aliceがカードを取る
  max_val = max(aN)
  Alice.append(max_val)
  aN.remove(max_val)
  if len(aN) > 0:
    # Aliceがカードを取った後Bobがカードを取る
    max_val = max(aN)
    Bob.append(max_val)
    aN.remove(max_val)

print(sum(Alice) - sum(Bob))

Submission status: Accepted

Solution code:
N = int(input())
n = map(int, input().split())
an = sorted(n, reverse=True)
i = 0
A = 0
B = 0
while i != N:
  A += an[i]
  i += 1
  if i != N:
    B += an[i]
    i += 1
print(A - B)

Submission status: Accepted

Solution code:
n=int(input())
l=sorted((list(map(int, input().split()))),reverse=1)
print(abs(sum(l[::2])-sum(l[1::2])))

Submission status: Accepted

Solution code:
N = int(input())
a = sorted(map(int, input().split()), reverse=True)
alice = a[0::2]
bob = a[1::2]

print(sum(alice) - sum(bob))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    num_list = list(map(int, input().split()))
    
    num_list.sort(reverse=True)

    alice, bob = 0,0

    for i in range(N):
        if i % 2 == 0:
            alice += num_list[i]
        else:
            bob += num_list[i]

    print(alice-bob)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

alice=0
bob=0

for i in range(n):
    if i%2==0:
        alice+=newL[i]
    elif i%2==1:
        bob+=newL[i]
print(alice-bob)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)

print(sum(a[0::2]) - sum(a[1::2]))

Submission status: Accepted

Solution code:
N = int(input())
a = [110]
a = list(map(int, input().split()))
a.sort(reverse=True)
 
Alis = 0
Bob = 0
for j in range(N):
  if j % 2 == 0:
    Alis += a[j]
  else:
    Bob += a[j]
    
print(Alis-Bob)

Submission status: Accepted

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

cards.sort(reverse=True)

for i in range(0, n):
    if (i % 2 == 0):
        a += cards[i]
    else:
        b += cards[i]

print(a - b)

Submission status: Accepted

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

alice = []
a.sort(reverse=True)
for i in range(0, N, 2):
    alice.append(a[i])
print(2 * sum(alice) - sum(a))

Submission status: Accepted

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

A.sort(reverse=True)
Alice = 0
Bob = 0

for i in range(N):
    if i%2 == 0:
        Alice += A[i]
    else :
        Bob += A[i]
print(Alice - Bob)

Submission status: Accepted

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

ans = 0
for i in range(n):
    if i % 2 == 0:
        ans += l[i]
    else:
        ans -= l[i]

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
# print(N)

card_list = list(map(int, input().split()))
# print(card_list)

A=0
B=0

for i in range(N):
    if i%2==0:
        A+=max(card_list)
        card_list.remove(max(card_list))
        # print(card_list)
    else:
        B+=max(card_list)
        card_list.remove(max(card_list))
        # print(card_list)

# print(A)
# print(B)

print(A-B)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
l=(list(map(int,input().split()))) 
l.sort(reverse=True)
for i in range(n):
    if i%2==1:
        l[i]=-l[i]
print(sum(l))

Submission status: Accepted

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

Alice = 0
Bob = 0
A.sort(reverse=True)
for i in range(len(A)):
    if i%2 == 0:
        Alice += A[i]
    else:
        Bob += A[i]
    
print(Alice-Bob)

Submission status: Accepted

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

Alice = 0
Bob = 0
A.sort(reverse=True)
for i in range(len(A)):
    if i%2 == 0:
        Alice += A[0]
    else:
        Bob += A[0]
    A.pop(0)
    
print(Alice-Bob)

Submission status: Accepted

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

Alice = 0
Bob = 0
for i in range(len(A)):
    m = max(A)
    if i%2 == 0:
        Alice += m
    else:
        Bob += m
    A.remove(m)
    
print(Alice-Bob)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
alice, bob = 0, 0
while(True):
    alice += max(A)
    A.remove(max(A))
    if not A: break
    bob += max(A)
    A.remove(max(A))
    if not A: break
print(alice - bob)

Submission status: Accepted

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

List.sort(reverse=True)

ans = sum(List[::2])-sum(List[1::2])

print(ans)

Submission status: Accepted

Solution code:
number=input()
number=int(number)
card=input().rstrip().split()
card=list(map(int,card))
alice=0
bob=0
for i in range(number):
    a=max(card)
    if i%2==0:
        alice+=a
    else:
        bob+=a
    del card[card.index(max(card))]
print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

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

card_list_ex = sorted(card_list, reverse=True)


alice,bob = 0,0
for i,j in enumerate(card_list_ex):
    if i % 2 == 0:
        alice += j
    else:
        bob += j
res = alice - bob
print(res)

Submission status: Accepted

Solution code:

n = int(input())
cards = sorted(list(map(int, input().split())), reverse=True)

alice = 0
bob = 0
for i in range(n):
    if i % 2 == 0:
        alice += cards[i]
    else:
        bob += cards[i]

print(alice - bob)

Submission status: Accepted

Solution code:

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

alice = 0
bob = 0
for i in range(n):
    if len(cards) == 0:
        break
    card = max(cards)
    cards.remove(card)
    if i % 2 == 0:
        alice += card
    else:
        bob += card

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

A.sort(reverse=True)
alice = sum(A[::2])
bob = sum(A[1::2])

print(alice - bob)

Submission status: Accepted

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

A = 0
B = 0

n = round(N/2+0.1)

while True:
  try:
    A = A + max(a)
    a.pop(a.index(max(a)))
    B = B + max(a)
    a.pop(a.index(max(a)))
  except:
    break

print(A-B)

Submission status: Accepted

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

Alice = 0
Bob = 0
for i in range(n):
    if i % 2 == 0: 
        Alice += max(a)
    else:
        Bob+= max(a)
    a.remove(max(a))

print(Alice-Bob)

Submission status: Accepted

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

Alice = []
Bob = []
for i in range(n):
    if i % 2 == 0: 
        Alice.append(max(a))
    else:
        Bob.append(max(a))
    a.remove(max(a))

print(sum(Alice)-sum(Bob))

Submission status: Accepted

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