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
A = sorted(A)
for i in range(n):
    if i % 2 == 0:
        alice += A[n - 1 - i]
    else:
        bob += A[n - 1 - i]
print(alice - bob)

Submission status: Accepted

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

bob = []
alice = []
for i in range(1, n+1):
    max_value = max(array)
    if i % 2 == 1:
        alice.append(max_value)
    else:
        bob.append(max_value)
    array.remove(max_value)

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    A = list(reversed(sorted([int(i) for i in input().split(maxsplit=N)])))
    print(sum(A[0::2]) - sum(A[1::2]))


resolve()

Submission status: Accepted

Solution code:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt, gcd
from copy import deepcopy
from functools import reduce



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

    print(a-b)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a_desc = sorted(A, reverse=True)
print(sum(a_desc[0::2])-sum(a_desc[1::2]))

Submission status: Accepted

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

alice = 0
bob = 0

a_desc = sorted(A, reverse=True)

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

print(alice - bob)

Submission status: Accepted

Solution code:
import math
def main():
  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)
main()

Submission status: Accepted

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

alice = 0
bob = 0
count = 0

for i in range(0, len(a)):
	if count % 2 == 0:
		alice += a.pop(0)
	elif count % 2 == 1:
		bob += a.pop(0)
	count += 1

print(alice - bob)

Submission status: Accepted

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

alice = 0
bob = 0

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

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(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:
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]
    As = sorted(As)

    turn = 0
    A = 0
    B = 0
    while As:
        if turn % 2 == 0:
            A += As.pop()
        else:
            B += As.pop()

        turn += 1
    print(A-B)




if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import sys
N = int(input())
array = list(map(int,input().split()))
sys.exit() if not (1 <= N <= 100) else ''
for I in range(len(array)):
    sys.exit() if not (1 <= array[I] <= 100) else ''

array.sort(reverse=True)
alice = 0
bob = 0
for J in range(len(array)):
    if J == 0 or J % 2 == 0:
        alice += array[J]
    else:
        bob += array[J]

print(alice - bob)

Submission status: Accepted

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

# check
res = 0
Alice_Turn = True
while A:
    max_a = max(A)
    if Alice_Turn:
        res += max_a
        Alice_Turn = False
    else:
        res -= max_a
        Alice_Turn = True
    A.remove(max_a)

print(res)

Submission status: Accepted

Solution code:
n=int(input())
a=map(int,input().split())
lis=list(a)
lis.sort()
ali=0
bob=0
for i in range(n):
  if i%2==0:
    ali+=lis.pop()
  else:
    bob+=lis.pop()
print(ali-bob)

Submission status: Accepted

Solution code:
n=int(input())

a_list=[int(i) for i in input().split()]
a_list.sort(reverse=True)


alice=[]
bob=[]
for i in range(n):
    if i%2==0:
        alice.append(a_list[i])
    else:
        bob.append(a_list[i])
        
print(sum(alice)-sum(bob))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(alice_sum - bob_sum)

Submission status: Accepted

Solution code:
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
#import string
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
def OutH(lst, deli=' '): print(deli.join(map(str, lst)))
def OutV(lst): print('\n'.join(map(str, lst)))
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

N = iIn()
A = iInLH()

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(reverse=True)

result = sum(a[::2]) - sum(a[1::2])

print(result)

Submission status: Accepted

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

a.sort(reverse=True)

Alice, Bob = 0, 0
for i in a[::2]:
    Alice += i
    
for i in a[1::2]:
    Bob += i

result = Alice - Bob

print(result)

Submission status: Accepted

Solution code:
def actual(N, A):
    A_desc = sorted(A, reverse=True)

    alice_cards = A_desc[::2]
    bob_cards = A_desc[1::2]

    return sum(alice_cards) - sum(bob_cards)

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

print(actual(N, A))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

alice=0
bob=0
a.sort(reverse=True)
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)

A,B=0,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 = map(int,input().split())

point_Alice = 0
point_Bob = 0

b = sorted(a,reverse=True)

while True:
    point_Alice += b.pop(0)
    if b == []:
        break
    point_Bob += b.pop(0)
    if b == []:
        break

ans = point_Alice - point_Bob
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#
# Author: Tetsuya Ishikawa <tiskw111@gmail.com>
# Date  : June 30, 2020
##################################################### SOURCE START #####################################################

N = int(input().strip())
An = list(map(int, input().strip().split()))

An = sorted(An, reverse=True)

p1 = sum(An[0::2])
p2 = sum(An[1::2])

print(p1 - p2)

##################################################### SOURCE FINISH ####################################################
# vim: expandtab tabstop=4 shiftwidth=4 fdm=marker

Submission status: Accepted

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

lis = sorted(lis, reverse = True)

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

print(a-b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, *aa = map(int, open(0).read().split())

aa.sort(reverse=True)

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

Submission status: Accepted

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

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

print(ali - bob)

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]
print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = []
a = input().split(' ')
a = [int(i) for i in a]
a = sorted(a, reverse=True)
Alice = 0
Bob = 0
for i in range(N):
  if i == 0:
    Alice += a[i]
  elif i%2 == 0:
    Alice += a[i]
  elif i%2 == 1:
    Bob += a[i]

print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

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

X=0
k=1
for a in A:
    X+=k*a
    k*=-1
print(X)

Submission status: Accepted

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

a.sort()
a.reverse()
print(sum([a[i] if i % 2 == 0 else -a[i] for i in range(n)]))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
Alice = 0
Bob = 0
i = 0
for i in range(0,N,2):
    Alice += a[i]
    if i+1 >= N:
        break
    Bob += a[i+1]
print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    N = II()
    A = LMIIS()
    A.sort(reverse=True)
    alice = sum(A[0::2])
    bob = sum(A[1::2])
    print(alice-bob)
    
main()

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()))
a.sort(reverse=True)
k=0
l=0

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
res = 0
for i in range(N - 1, -1, -2):
    res += A[i]
for i in range(N - 2, -1, -2):
    res -= A[i]
print(res)

Submission status: Accepted

Solution code:
#n , m , l = map(int , input().split())

# list_n = list(map(int , inpuut().split()))<Paste>

#n = input()
# list = [input() for i in range(N)

#list = [[i for i in range(N)] for _ in range(M)]


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

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

Submission status: Accepted

Solution code:
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:
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
flag = True
for a in sorted(a_list, reverse=True):
    if flag:
        ans += a
    else:
        ans -= a
    flag = not flag
print(ans)

Submission status: Accepted

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

alice = 0
bob = 0
flag = True
for a in sorted(a_list, reverse=True):
    if flag:
        alice += a
    else:
        bob += a
    flag = not flag
print(alice-bob)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a_li = [int(w) for w in input().split()]
a_li.sort(reverse=True)

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

Submission status: Accepted

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

Submission status: Accepted

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

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==0 or i%2==0:
        A+=lst[i]
    else:
        B+=lst[i]

print(int(A)-int(B))

Submission status: Accepted

Solution code:
N, *a = map(int, open(0).read().split())

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

Submission status: Accepted

Solution code:
N = int(input())

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

a.sort(reverse=True)

i = 0
A = 0
B = 0

for k in a:
	if i % 2 == 0:
		A += k
	else:
		B += k
	i += 1

print(A - B)

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 = 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:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
a = np.array(a)
alice = a[0::2]
bob = a[1::2]
print(sum(alice)-sum(bob))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

    score_a = sum(a[::2])
    score_b = sum(a[1::2])
    print(score_a - score_b)

if __name__ == '__main__':
    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.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(reverse=True)
p1 = 0
p2 = 0
for i in range(1,n+1):
    if i % 2 == 0:
        p2 += a[i-1]
    else:
        p1 += a[i-1]

print(p1-p2)

Submission status: Accepted

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

alice = 0
bob = 0
A.sort(reverse=True)
for ix, a in enumerate(A):
    if ix & 1:
        bob += a
    else:
        alice += a

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())
A = list(map(int,input().split()))
A = sorted(A,reverse = True)
A.insert(N,0)
ans = 0
for i in range(0,N,2):
	ans += (A[i] - A[i+1])
print(ans)

Submission status: Accepted

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

Alice = 0
Bob = 0
for i, card in enumerate(cards):
    if i % 2 == 0:
        Alice += card
    else:
        Bob += card
print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from sys import stdin
data = stdin.readlines()

a = int(data[0])
b = [int(s) for s in data[1].split()]

i = 1
alice = 0
bob = 0
while i <= math.ceil(a/2):
    alice += b.pop(b.index(max(b)))
    if len(b) >= 1:
        bob  += b.pop(b.index(max(b)))
    i += 1
print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

a, b = 0, 0
for i in range(N):
    if i % 2 == 0:
        a += A.pop(0)
    else:
        b += A.pop(0)

print(a-b)

Submission status: Accepted

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
alc = 0
bb = 0
for i in range(0, n, 2):
    alc += A[i]
for j in range(1, n, 2):
    bb += A[j]
print(alc - bb)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(alice-bob)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort() 
alice_sum=0
bob_sum=0
if len(a)%2==0:
  for i in range(0,n,2):
    bob_sum+=a[i]
  for l in range(1,n,2):
    alice_sum+=a[l]
else:
  for i in range(0,n,2):
    alice_sum+=a[i]
  for k in range(1,n,2):
    bob_sum+=a[k]
    
print(alice_sum-bob_sum)

Submission status: Accepted

Solution code:
N=int(input())
a=[int(x) for x in input().split()]
Alice=0
Bob=0
for i in range(N):
  if i%2==0:
    Alice=Alice+max(a)
    a.remove(max(a))
  else:
    Bob=Bob+max(a)
    a.remove(max(a))
print(Alice-Bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a = int(input()), 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)
# print(bob)
print(alice - bob)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
Sabun = 0
for i in range(len(A)):
    if i % 2 == 0:
        Sabun += A[i]
    elif i % 2 == 1:
        Sabun -= A[i]
print(Sabun)

Submission status: Accepted

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

aSorted = sorted(a, reverse=True)

alice = 0
bob = 0

for i in range(N):
    # アリスのターン
    if i % 2 == 0:
        alice += aSorted[i]
    # ボブのターン
    else:
        bob += aSorted[i]

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

while True:
  alice += a[0]
  del a[0]
  if a == []:
    break
  bob += a[0]
  del a[0]
  if a == []:
    break

print(alice - bob)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
aa=sorted(a)
ans1=0
ans2=0
for i in range(n):
  if i%2==0:
    ans1+=aa[i]
  else:
    ans2+=aa[i]
print([ans2-ans1,ans1-ans2][n%2])

Submission status: Accepted

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


if __name__ == "__main__":
    main()

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())
card=list(map(int,input().split()))
card.sort(reverse=True)
for i in range(1,n,2):
    card[i]*=(-1)
print(sum(card))

Submission status: Accepted

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

Submission status: Accepted

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

a.sort(reverse=True)

cnt = 0
Alice = 0
Bob = 0
while cnt < n:
    cnt += 1
    if cnt % 2 != 0:
        Alice += a[cnt-1]
    else:
        Bob += a[cnt-1]

print(Alice - Bob)

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:
N = int(input())
numlist=list(map(int,input().split()))#リストに対してしか実行できない関数を使うため、入力した値をリスト化する
sortnumlist=sorted(numlist,reverse=True)#リストの中身を降順にしたやつをsortnumlistと言う変数名つけた

#リストのインデックス０、２、４・・・の合計がAliceの得点、１、３、５・・・の合計がBobの得点に等しい

alice_total = 0#Aliceの得点を初期化
bob_total = 0#Bobの得点を初期化
for x,y in enumerate (sortnumlist):#リストの要素のインデックスと値を別々に取り出す
    if x %2 ==0:
        alice_total = alice_total + y
    elif x %2 ==1:
        bob_total = bob_total + y
        
#print(alice_total)
#print(bob_total)

answer = alice_total  - bob_total
print(answer)

Submission status: Accepted

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

ans = 0
k = 0
for i in range(n):
  res = max(a)
  if k % 2 == 0:
    ans += res
  else:
    ans -= res
  a.remove(res)
  k += 1
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

S.sort(reverse=True)
if N%2 == 0:
    ans = 0
else:
    ans = S[-1]
for i in range(N//2):
    ans += S[2*i]-S[2*i+1]
print(ans)

Submission status: Accepted

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

print(scorea-scoreb)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = input().split()
a = list(map(int,input().split()))
a.sort(reverse=True)
Bob = 0
Alice = 0
for i,b in enumerate(a):
    if i % 2 == 0:
        Alice += b
    else:
        Bob += b

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())
al = list(map(int, input().split()))

als = sorted(al,reverse = True)

alice = sum(als[::2])
bob =  sum(als[1::2])

print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

a.sort()
a = a[::-1]

a_total = 0
b_total = 0
for i in range(N):
    if i%2==0:
        a_total += a[i]
    else:
        b_total += a[i]

print(a_total-b_total)

Submission status: Accepted

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

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.sort(reverse=True)
alice = sum(a[::2])
bob = sum(a[1::2])

print(alice-bob)

Submission status: Accepted

Solution code:
#カードの枚数N
N = int(input())

#カードに書かれる数a
a = list(map(int, input().split()))
a = sorted(a, reverse = True)

#print(N)
#print(a)

Alice = 0
Bob = 0

#ターン数x
x = 0

#pop(n) ➡　配列のn番目の要素を抜き取る
while not(len(a) == 0):
    if x%2 == 0:
        Alice += a.pop(0)

        #print(Alice)
        x += 1
        #a = [:a(max)]

    else:
        Bob += a.pop(0)
        #print(Bob)
        x += 1

print(Alice - Bob)

Submission status: Accepted

Solution code:
# 入力受け取り
N = int(input())
Cards = list(map(int,input().split()))
# 合計値初期化
sum_A = 0
sum_B = 0
#添え字
t = 0
while not(max(Cards) == 0):
        if t % 2 == 0:
            sum_A += max(Cards)
            a = Cards.index(max(Cards))
            Cards[a] = 0
            t += 1
        else:
            sum_B += max(Cards)
            a = Cards.index(max(Cards))
            Cards[a] = 0
            t += 1

print(sum_A - sum_B)

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.pop(0)
  else:
    Bob += a.pop(0)

print(Alice - Bob)

Submission status: Accepted

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

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 = sorted(list(map(int,input().split())),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()))

Alice = 0
Bob = 0

#降順に並べることが完了
ld = sorted(a, reverse=True)

Alice = ld[:: 2]
# print(Alice)

Bob = ld[1:: 2]
# print(Bob)

Alice_a = sum(Alice)
Bob_a = sum(Bob)


print(Alice_a - Bob_a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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:
import sys
input = sys.stdin.readline

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

A.sort(reverse=True)
alip = sum(A[i] for i in range(len(A)) if i % 2 == 0)
bobp = sum(A[i] for i in range(len(A)) if i % 2 == 1)
diff = alip - bobp
print(diff)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

# A = sorted(A, reverse=True)
# 破壊ソートの方が高速
A.sort(reverse=True)
alip = sum(A[i] for i in range(len(A)) if i % 2 == 0)
bobp = sum(A[i] for i in range(len(A)) if i % 2 == 1)
diff = alip - bobp
print(diff)

Submission status: Accepted

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