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()))

a.sort(reverse = True)

Ali = 0
Bob = 0

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

Submission status: Accepted

Solution code:

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

Al = sum(a[::2])
Bo = sum(a[1::2])

print(Al-Bo)

Submission status: Accepted

Solution code:
import sys
import math
n = int(input())
li = list(map(int, input().split()))
li.sort(reverse=True)
alice = 0
bob = 0
for i in range(0, len(li) - 1, 2):
    alice += li[i]
    bob += li[i + 1]
if (len(li) % 2 != 0):
    alice+=li[-1]
print(alice-bob)

Submission status: Accepted

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

A_score = 0
B_Score = 0

a = sorted(a, reverse=True)

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

print(A_score - B_Score)

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
s_a_list = sorted(a_list)
alice = 0
bob = 0
while len(s_a_list)>1:
  alice += s_a_list.pop(-1)
  bob += s_a_list.pop(-1)
if len(s_a_list) != 0:
  alice += s_a_list.pop(-1)
print(alice-bob)

Submission status: Accepted

Solution code:
import heapq
n = int(input())
a = list(map(lambda x: int(x)*(-1), input().split()))

heapq.heapify(a)
i = 1
alice = 0
bob = 0
while i <= n:
  if i % 2 == 1:
    alice += heapq.heappop(a)*(-1)
  else:
    bob += heapq.heappop(a)*(-1)
  i += 1
print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int, input().split()))
if len(a) % 2 != 0 :
    a.append(0)
a=sorted(a, reverse=True)
al=a[0::2]
print(sum(al)*2 - sum(a))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
Alice = 0; Bob = 0
for i in range(N):
    if i%2 == 0:
        Alice += A.pop()
    else:
        Bob += A.pop()
print(Alice - Bob)

Submission status: Accepted

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

alice = []
bob = []

if n%2 == 0:
  while(len(a)>0):
    alice.append(a.pop())
    bob.append(a.pop())
else:
  alice.append(a.pop())
  while(len(a)>0):
    bob.append(a.pop())
    alice.append(a.pop())
print(sum(alice)-sum(bob))

Submission status: Accepted

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

i = 0
AliceScore = 0
BobScore = 0

while i <= n-1:
    if i % 2 == 0:
        AliceScore += org_list[i]
    else:
        BobScore += org_list[i]
    i += 1

print(AliceScore - BobScore)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
N = ri()
a = sorted(ri_(), reverse=True)
print(sum(a[0::2]) - sum(a[1::2]))

Submission status: Accepted

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

alice = 0
bob = 0

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

print(alice-bob)

Submission status: Accepted

Solution code:
n = int(input())

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

srt_as = sorted(As, reverse=True)

Alice = 0
Bob = 0

for i in range(n):
    if i % 2 == 0:
        Alice += srt_as[i]
    else:
        Bob += srt_as[i]

print(Alice-Bob)

Submission status: Accepted

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

A = sorted(a, reverse=True)

Alice = 0
Bob = 0


for i in A[0::2]:
  Alice += i
  
for _ in A[1::2]:
  Bob += _
  
ans = Alice -Bob
  
print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

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

if len(a) % 2 != 0:
  a.append(0)
  
a.sort()

for i in range(int(len(a) / 2)):
  total += a[2 * i] - a[2 * i + 1]

print(total * (-1))

Submission status: Accepted

Solution code:
n = int(input())

arr = list(map(int, input().split()))
arr.sort(reverse=True)

a_point = 0
b_point = 0
for i in range(len(arr)):
    if i % 2 == 0:
        a_point += arr[i]
    else:
        b_point += arr[i]

print(a_point - b_point)

Submission status: Accepted

Solution code:
n = int(input())

arr = list(map(int, input().split()))
arr.sort()
arr.reverse()

a_point = 0
b_point = 0
for i in range(len(arr)):
    if i % 2 == 0:
        a_point += arr[i]
    else:
        b_point += arr[i]

print(a_point - b_point)

Submission status: Accepted

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

alice = 0
bob = 0

i = 0
lim = n // 2 * 2

while i < lim:
    alice += a[i]
    bob += a[i+1]
    i += 2

if n % 2 == 1:
    alice += a[n-1]

print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def main():
    #s = sys.stdin.readlines()
    N = input() # number of card
    A = sorted(list(map(int,input().split())), reverse = True) # card
    Alice = sum([ a for i,a in enumerate(A) if i%2 == 0 ])
    Bob = sum([ a for i,a in enumerate(A) if i%2 == 1 ])
    print(Alice-Bob)

if __name__ == "__main__":
    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.pop(0)
    else:
        bob += a.pop(0)
print(alice-bob)

Submission status: Accepted

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

print(ca-cb)

Submission status: Accepted

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

card.sort(reverse=True)

asum = 0
bsum = 0
for i in range(n):
  if i%2==0:
    asum += card[i]
  else:
    bsum += card[i]

print(asum-bsum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

x = len(a)

Alice = 0
Bob = 0

for i in range(x):
    for j in range(x - 1 - i):
        if a[j] < a[j + 1]:
            tmp = a[j]
            a[j] = a[j + 1]
            a[j + 1] = tmp

for i in range(x):
    if i % 2 == 0:
        Alice += a[i]
    else:
        Bob += a[i]

   
z = Alice - Bob

print(z)

Submission status: Accepted

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

A = 0
B = 0
for i, x in enumerate(sorted(a)[::-1]):
    if i % 2 == 0:
        A += x
    else:
        B += x
print(A-B)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
c = input().split()
card = np.array(c, dtype=np.int64)
alice = 0
bob = 0
card = np.sort(card)[::-1]


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

print(alice - bob)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    a = [i for i in map(int, input().split())]
    a = sorted(a, reverse=True)
    alice = sum([j for i, j in enumerate(a) if i % 2 == 0])
    bob = sum([j for i, j in enumerate(a) if i % 2 != 0])
    print(alice - bob)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
card_list = [int(n) for n in input().split()]

card_list = sorted(card_list, reverse=True)
point_a = sum(card_list[::2])
point_b = sum(card_list[1::2])
print(point_a - point_b)

Submission status: Accepted

Solution code:
n = int(input())

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

card.sort(reverse = True)

a = 0

b = 0

turn  = 0

for i in card:
    if turn == 0:
        a += i
        turn = 1
    else:
        b += i
        turn = 0
        
print(a-b)

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    a = [int(i) for i in input().split()]
    a = sorted(a, reverse=True)
    alice = a[0::2]
    bob = a[1::2]
    print(sum(alice) - sum(bob))

resolve()

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
A = 0
B = 0
a = sorted(a)
for i, e in enumerate(a):
    if i % 2 == 0:
        A += e
    else:
        B += e
print(abs(A - B))

Submission status: Accepted

Solution code:
n = int(input())
l = [int(x) for x in input().split()]
a = 0
b = 0
for i in range(n):
  if i % 2 == 0:
    a += max(l)
    l.remove(max(l))
  elif i % 2 == 1:
    b += max(l)
    l.remove(max(l))
print(a-b)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(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()))
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()
B = A[0::2]
b = sum(B)
C = A[1::2]
c = sum(C)
if b >= c:
  print(b-c)
else:
  print(c-b)

Submission status: Accepted

Solution code:
import math

N = input()
N = int(N)
list = input().split()
for i in range(N):
    list[i] = int(list[i])

list.sort(reverse=True)

listA=[]
listB=[]
for i in range(math.floor(N/2)):
    listA.append(list[2*i])
    listB.append(list[2*i + 1])

Asum = sum(listA)
Bsum = sum(listB)
if(N%2==1):
    Asum += list[N-1]

print(Asum - Bsum)

Submission status: Accepted

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

acnt =0
bcnt=0
a.sort(reverse=True)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

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

A.sort(reverse=True)

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

ans = alice - bob
print(ans)

Submission status: Accepted

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

alice = []
bob = []


while len(a) > 0:
  alice.append(max(a))
  a.remove(max(a))
  if len(a) > 0:
    bob.append(max(a))
    a.remove(max(a))
  else:
    break
    
  
print(sum(alice)-sum(bob))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

i = 0
A = 0
B = 0
while i < N:
    A += a[i]
    if i+1 < N:
        B += a[i+1]
    i += 2
print(A - B)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().strip()

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

    a_lst = sorted(a_lst)
    alice_score = 0
    bob_score = 0
    for _ in range(0,N,2):
        alice_score += a_lst.pop() if a_lst else 0
        bob_score += a_lst.pop() if a_lst else 0
    print(alice_score - bob_score)

main()

Submission status: Accepted

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

def main(n,a):
    a.sort(reverse=True)
    nloop=n//2
    apoint=0
    bpoint=0
    l=0
    while(l<nloop):
        apoint+=a[l*2]
        bpoint+=a[l*2+1]
        l+=1
    if(n%2==1):
        apoint+=a[n-1]
    return apoint-bpoint


if __name__=='__main__':
    n,a = readinput()
    ans=main(n,a)
    print(ans)

Submission status: Accepted

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

sorted_A = sorted(A, reverse=True)

Alice_sum = 0
Bob_sum = 0
for i in range(len(sorted_A)):
    if i % 2 == 0:
        Alice_sum = Alice_sum + sorted_A[i]
    else:
        Bob_sum = Bob_sum + sorted_A[i]

print(Alice_sum - Bob_sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b, c = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    re = 0
    B = sorted(A, reverse=True)

    for i in range(len(B)):
        if i % 2 == 0:
            re += B[i]
        else:
            re -= B[i]
    print(re)
resolve()

Submission status: Accepted

Solution code:
def resolve():
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b, c = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    sumA=0
    sumB=0
    B = sorted(A, reverse=True)
    turnB = False

    for i in B:
        if turnB == False:
            sumA += i
            turnB = True
        else:
            sumB += i
            turnB = False

    print(int(sumA - sumB))


resolve()

Submission status: Accepted

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

Gap = sum(A)
n = N//2

if N!=1:
    for i in range(n):
       Gap += -2*A[1+2*i]

print(Gap)

Submission status: Accepted

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

Gap = sum(A)

if N!=1:
    for i in range(N//2):
       Gap += -2*A[1+2*i]

print(Gap)

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)-Alice

print(Alice-Bob)

Submission status: Accepted

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

if N == 1:
	print(A[0])
else:
	Alice = sum(A[0::2])
	Bob = sum(A[1::2])
	print(Alice-Bob)

Submission status: Accepted

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    a_arr = list(map(int,_in[1].split(' ')))
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    a_arr.sort(reverse=True)
    alice_card = a_arr[0::2]
    bob_card = a_arr[1::2]
    cnt = sum(alice_card) - sum(bob_card)
    ## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

Alice = 0
Bob = 0

for i in range(N):
  MaxPoint = max(cards)
  
  if i % 2 == 0:
    Alice += MaxPoint
  else:
    Bob   += MaxPoint

  cards.remove(MaxPoint)

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 = sorted(list(map(int, input().split())), reverse=True)
print(sum(A[::2]) - sum(A[1::2]))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
alice,bob=0,0
u=sorted(LI(),reverse=True)
for i in range(n):
    if i%2==0:
        alice+=u[i]
    else:
        bob+=u[i]
print(alice-bob)

Submission status: Accepted

Solution code:
N = int(input())
num_list = [int(e) for e in input().split()]

S = sorted(num_list, reverse=True)

Alice = S[::2]
Bob = S[1::2]

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

Submission status: Accepted

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

a = sorted(a, reverse=True)

alice = [a[2*i] for i in range(N) if 2*i<N]
bob = [a[2*i+1] for i in range(N) if (2*i+1)<N]

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

Submission status: Accepted

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

alice_count = 0
bob_count = 0

for i in range(0,N):
    #手順を調べる
    if i%2==0: # Aliceの番
        alice_count += a_sorted[i]
    else: #Bobの番
        bob_count += a_sorted[i]
        
print(alice_count-bob_count)

Submission status: Accepted

Solution code:
n = int(input())

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

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())
li = list(map(int,input().split()))
ca=0
cb=0
li.sort(reverse=True)
for i in range(len(li)):
    #print(i)
    if i%2==0:
        ca+=li[i]
    else:
        cb+=li[i]
print(ca-cb)

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()
a,b = 0,0
cards = list(map(int, input().split()))
for i, c in enumerate(reversed(sorted(cards))):
  if i % 2 == 0:
    a += c
  else:
    b += c
print(a-b)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(map(int,input().split()),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())
x = list(map(int, input().split()))

x.sort()
x.reverse()

A = []
B = []
for i in range(len(x)):
  if i%2==0:
    m = max(x)
    A.append(m)
    x.remove(m)
  else:
    m = max(x)
    B.append(m)
    x.remove(m)

C = sum(A) - sum(B)
print(C)

Submission status: Accepted

Solution code:
# coding: utf-8
"""this is python work script"""

def find_score(card_list):
    """return score list about a and b"""
    sum_a, sum_b = 0, 0
    card_list.sort()
    
    for i in range(len(card_list)):
        if i % 2 == 0:
            sum_a += card_list.pop()
        else:
            sum_b += card_list.pop()
            
    return sum_a, sum_b

def solve(card_list):
    """solve problem"""
    a_score, b_score = find_score(card_list)
    diff_score = a_score - b_score
    
    return diff_score

def main():
    """main method"""
    _ = input()
    list_cards = list(map(int, input().split(' ')))
    answer = solve(list_cards)
    print(answer)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
"""this is python work script"""

def find_score(N, card_list):
    """return score list about a and b"""
    sum_a, sum_b = 0, 0
    card_list.sort()
    for i in range(N):
        if i % 2 == 0:
            sum_a += card_list.pop()
        else:
            sum_b += card_list.pop()
    return sum_a, sum_b

def solve(num, card_list):
    """solve problem"""
    a_score, b_score = find_score(num, card_list)
    diff_score = a_score - b_score
    return diff_score

def main():
    """main method"""
    num_cards = int(input())
    list_cards = list(map(int, input().split(' ')))
    answer = solve(num_cards, list_cards)
    print(answer)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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())
a = list(map(int, input().split()))
alice = 0
bob = 0

a.sort(reverse = True)
for i in range(0,n,2):
  alice += a[i]
for i in range(1,n,2):
  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=0
bob=0
for i in range(0,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)
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:
cnt = int(input())
numlist = list(map(int,input().split()))
list.sort(numlist, reverse=True)
A = 0
B = 0

for x in range(cnt):
    if x % 2 == 0:
        A += numlist[x]
    else:
        B += numlist[x]

print(A-B)

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_sorted = sorted(a, reverse=True)

A_point = 0
B_point = 0

for i in range(0, N):
    if i%2 == 0:
        A_point += a_sorted[i]
    else:
        B_point += a_sorted[i]

print(A_point-B_point)

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


def read():
    N = int(input().strip())
    A = (map(int, input().strip().split()))
    return N, A

def solve(N, A):
    A = sorted(A, reverse=True)
    alice = 0
    bob = 0
    alice_turn = True
    for a in A:
        if alice_turn:
            alice += a
        else:
            bob += a
        alice_turn = not alice_turn
    return alice - bob


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))

Submission status: Accepted

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

Submission status: Accepted

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

list_a.sort(reverse=True)

sam_a=0
sam_b=0

for i in range(N):
    if i%2 == 0:
        sam_a+=list_a[i]
    else:
        sam_b+=list_a[i]

print(sam_a-sam_b)

Submission status: Accepted

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

A=0
B=0
a=sorted(a,reverse=True)

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 = [int(i) for i in input().split()]

a_list.sort(reverse=True)
alice, bob = 0, 0
for idx, a in enumerate(a_list):
    if idx % 2 == 0:
        alice += a
    else:
        bob += a
print(alice - bob)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
ans = 0
for i in range(0, n, 2):
    ans += a[i]
for i in range(1, n, 2):
    ans -= a[i]
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(n):
    if i%2 == 0:
        Alice += a[i]
    else:
        Bob += a[i]

print(Alice-Bob)

Submission status: Accepted

Solution code:
N=int(input())
A=sorted(list(map(int, input().split())), reverse=True)
Bob=0
Alice=0
for i in range(len(A)):
  # print(i)
  if i == 0 or 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()))
sortedA=sorted(A, reverse=True)
Bob=0
Alice=0
for i in range(len(A)):
  # print(i)
  if i == 0 or i%2==0:
    Alice+=sortedA[i]
  else:
    Bob +=sortedA[i]
print(Alice-Bob)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
Alice = 0
Bob = 0
b = 1
for i in range(N):
  if b: # Aliceのターン
    Alice += a[i]
  else: # Bobのターン
    Bob += a[i]
  b = 0 if b == 1 else 1

print(Alice-Bob)

Submission status: Accepted

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

def sum(a):
    max_value = max(a)
    ind = a.index(max_value)
    a[ind] = 0
    return a,max_value

Asum = 0
Bsum = 0
max_value = 100
while max_value > 0:
    a,max_value = sum(a)
    Asum += max_value
    a,max_value = sum(a)
    Bsum += max_value

print(Asum - Bsum)

Submission status: Accepted

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

print(A - B)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))[::-1]
A = 0
B = 0

for i in a [::2]:
    A += i
for i in a [1::2]:
    B += i

print(A - B)

Submission status: Accepted

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

alice = sorted(a)[::2]
bob = sorted(a)[1::2]

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

Submission status: Accepted

Solution code:
# a = int(input())
# b,c = map(int, input().split())
# s = input()
# print('{} {}'.format(a+b+c,s))
#
# a,b = map(int, input().split())
# if a*b%2 == 0:
#     print("Even")
# else :
#     print("Odd")
# l = list(input())
# l_new = [int(n) for n in l]
# count = 0
# for i in l_new:
#     if i == 1:
#         count += 1
# print(count)
# #Maxの答えを先に宣言して上限を設けておく
# ans = 10 **9
# N = int(input())
# A = list(map(int,input().split()))
# for i in A:
#     p = 0
#     while i % 2 ==0:
#         i //=2
#         p += 1
#     if p < ans:
#         ans = p
#         #一度ansに格納して大小の比較を行っている
# print(ans)

#切り捨て除算


# a = int(input())
# b = int(input())
# c = int(input())
# X = int(input())
# count = 0
# for i in range(a+1):
#     x = 500 * i
#     for j in range(b+1):
#         y = 100 * j
#         for k in range(c+1):
#             z = 50 * k
#             if x+y+z == X :

N = int(input())
l = list(map(int,input().split()))
l_r = sorted(l,reverse=True)
Alice = l_r[::2]
Bob = l_r[1::2]

m =0
n = 0
for i in Alice:
    m += i
for j in Bob:
    n += j
print(m-n)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
al=0
bo=0
a.sort()
for i in range(n):
  if i%2==0:
    al+=a[-i-1]
  else:
    bo+=a[-i-1]
print(al-bo)

Submission status: Accepted

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

alices_score = sum([x if i % 2 == 0 else 0 for i, x in enumerate(l)])
bobs_score = sum([x if i % 2 != 0 else 0 for i, x in enumerate(l)])

print(alices_score - bobs_score)