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

li.sort()
li.reverse()
ans=0

for (i,c)in zip(range(0,n),li):
  if i%2==0:
    ans+=c
  else:
    ans-=c

print(ans)

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

Submission status: Accepted

Solution code:
def ABC_88_B():
    N=int(input())
    A = input().split()
    A = [int(s) for s in A]
    A.sort()
    alice=0
    bob=0

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

    print(abs(alice-bob))


if __name__ == '__main__':

    ABC_88_B()

Submission status: Accepted

Solution code:
n = int(input())
A = sorted(map(int, input().split()))[::-1]
# print(A)
loop = 0
scoreA = 0
scoreB = 0
for e in A:
    if loop % 2 == 0:
        scoreA += e
    else:
        scoreB += e
    loop += 1
print(scoreA - scoreB)

Submission status: Accepted

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

Alice = 0
Bob = 0

if N % 2 == 0:
    for _ in range(int(N / 2)):
        Max = max(list_a)
        Alice += Max
        list_a.remove(Max)

        Max = max(list_a)
        Bob += Max
        list_a.remove(Max)

else:
    for _ in range(int((N - 1) / 2)):
        Max = max(list_a)
        Alice += Max
        list_a.remove(Max)

        Max = max(list_a)
        Bob += Max
        list_a.remove(Max)

    Alice += list_a[0]

print(Alice - Bob)

Submission status: Accepted

Solution code:
n = int(input())
c = [int(i) for i in input().split()]
c.sort(reverse=True)
a = []
b = []
for i in range(n):
    if i % 2 == 0:
        a.append(c[i])
    else:
        b.append(c[i])
print(sum(a) - sum(b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
str_list = input().split()
num_list = [int(a) for a in str_list]
Alice = 0
Bob = 0
count = 1
while num_list:
    temp = max(num_list)
    if count % 2 != 0:
        Alice += temp
    else:
        Bob += temp
    num_list.remove(temp)
    count += 1

print(Alice - Bob)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in 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()))

Alice = 0
Bob = 0

while len(A) != 0:
    Alice += max(A)
    A.remove(max(A))
    if len(A) == 0:
        break
    Bob += max(A)
    A.remove(max(A))

print("{}".format(Alice-Bob))

Submission status: Accepted

Solution code:
def solve(n, a_list):
    tmp = sorted(a_list, reverse=True)
    
    alice_score = sum([x for i, x in enumerate(tmp) if i % 2 == 0])
    bob_score = sum([x for i, x in enumerate(tmp) if i % 2 == 1])
    return alice_score - bob_score

if __name__ == "__main__":
    n = int(input())
    a_list = [int(i) for i in input().split()]
    print(solve(n, a_list))

Submission status: Accepted

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

a.sort(reverse = True)
alice_score = 0
bob_score = 0
for i in range(n):
	if i % 2 == 0:
		alice_score += a[i]
	else:
		bob_score += a[i]
print(alice_score - bob_score)

Submission status: Accepted

Solution code:
n = int(input())

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


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

Submission status: Accepted

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

b = sorted(a, reverse=True)

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

Submission status: Accepted

Solution code:
N=int(input())
ls=input().split()
l=[ int(v) for v in ls ]

l.sort(reverse=True)

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

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

ali_sum = 0
bob_sum = 0

for index, card in enumerate(sorted(card_list)):
    if index % 2 == 1:
        ali_sum +=  card
    else:
        bob_sum += card

print(abs(ali_sum - bob_sum))

Submission status: Accepted

Solution code:
from sys import stdin
def I(): return int(stdin.readline().rstrip())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

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

print(alice-bob)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
num = int(input())
s = sorted(list(map(int,input().split())),reverse=True)
alice,bob = 0,0
for i,j in enumerate(s):
    if i % 2 == 0:
        alice += j
    else:
        bob += j
print(alice - bob)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
A.reverse()
cntA = 0
cntB = 0
flag = 0
for a in A:
    if flag == 0:
        cntA += a
        flag = 1
    else:
        cntB += a
        flag = 0
print(cntA-cntB)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    sum_a += max(a)
    a[a.index(max(a))] = 0
    sum_b += max(a)
    a[a.index(max(a))] = 0

print(sum_a - sum_b)

Submission status: Accepted

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

sorted_nums = sorted(nums, reverse=True)

a = 0
b = 0

def calSumOfDig(n):
    total = 0
    for i in n:
        total += i
    return total


ls = calSumOfDig(sorted_nums[0::2]) - calSumOfDig(sorted_nums[1::2])

print(ls)

Submission status: Accepted

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

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# list = list(map(int, input().split()))

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

## Logic

alice = 0
bob = 0

A.sort(reverse=True)
for i in range(0,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()))
s_a=sorted(a)[::-1]
print(sum(s_a[::2])-sum(s_a[1::2]))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a, reverse=True)
    alice = 0
    bob = 0
    for i in range(n):
        if i % 2 == 0:
            alice += a_sort[i]
        else:
            bob += a_sort[i]
    res = alice - bob
    print(res)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    L = list(map(lambda x: -x, L))
    heapify(L)

    alice = 0
    bob = 0
    alice_turn = True
    while L:
        num = - heappop(L)
        if alice_turn:
            alice += num
        else:
            bob += num
        alice_turn = not alice_turn
    print(alice - bob)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

num = int(input())
s = sorted(list(map(int,input().split())) ,reverse=True)
#print(s)

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

Submission status: Accepted

Solution code:
N = int(input())
a = [0]*N
tmp = input().split()
for i in range(N):
    a[i] = int(tmp[i])

a.sort(reverse=True)
A = B = 0


for i in range(0,N//2):
    A += a[2*i]
    B += a[2*i+1]
if N%2 == 1:
    A += a[N-1]

print(A-B)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
sumA = 0
sumB = 0

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

print(sumA-sumB)

Submission status: Accepted

Solution code:
_, *a = map(int, open(0).read().split())
a.sort()
print(sum(a[-1::-2]) - sum(a[-2::-2]))

Submission status: Accepted

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

score_a = 0
score_b = 0

while len(A):
	max_i = A.index(max(A))
	score_a += A.pop(max_i)

	if len(A):
		max_i = A.index(max(A))
		score_b += A.pop(max_i)

print(score_a - score_b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = int(input())
alist = input().split(" ")
alist = list(map(int,alist))

def max_number(l):
    sum = max(l)
    l.remove(sum)
    return sum

def alice_bob(n,m):
    q = 0
    a = 0
    b = 0
    while q <= n-1:
        temp = max_number(m)
        a += temp
        temp = 0
        q += 1
        if q <= n-1:
            temp = max_number(m)
            b += temp
            temp = 0
            q += 1
    sub = a-b
    return sub

ans = alice_bob(num,alist)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
alice = 0
bob = 0
a.sort()
for i in range(n):
    if i%2==0:
        alice += a[-1]
        a.pop()
    elif i%2==1:
        bob += a[-1]
        a.pop()
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:
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    ans = 0
    for i, num in enumerate(sorted(a)[::-1]):
        if i % 2 == 0:
            ans += num
        else:
            ans -= num
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[10]:


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


# In[11]:


a_s = sorted(a, reverse=True)
alice = sum(a_s[::2])
bob = sum(a_s[1::2])
print(alice-bob)


# In[ ]:

Submission status: Accepted

Solution code:
N = int(input())
a = [int(k) for k in input().split()]
a.sort(reverse = True)
sub = 0

for i in range(N//2):
    sub += a[2*i] - a[2*i +1]
if (N%2 == 1):
    sub += a[-1]

print(sub)

Submission status: Accepted

Solution code:
#Card Game for Two
n=int(input())  #N<=100
a = list(map(int,input().split()))

a.sort(reverse=True)
alice=a[::2]
alice=sum(alice)

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

Submission status: Accepted

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

a=sorted(a, reverse=True)
A=[]
B=[]

for i in range(N):
    if i%2==0:
        A.append(a[i])
    else:
        B.append(a[i])

print(sum(A)-sum(B))

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(map(int, input().split()), reverse=True)
alice = 0
bob = 0
for i, v in enumerate(a):
  if i & 1:
  	bob += v
  else:
    alice += v
 
print(alice - bob)

Submission status: Accepted

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

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 li():
    return list(map(int, input().split()))


def mi():
    return map(int, input().split())


def ii():
    return int(input())


N = ii()
a = li()

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

alice, bob = 0, 0

for i in range(len(a)):
    if i % 2 == 0:
        alice += max(a)
        a.remove(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 = 0
Bob = 0

a = sorted(a, reverse=True)

for i in range(0,N,2):
    Alice += a[i]
    if i == N - 1:
        continue
    Bob +=a[i + 1]

print(Alice - Bob)

Submission status: Accepted

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

card.sort(reverse=True)

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

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    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)
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import deque

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
a = LI()
a = sorted(a)

d = a

x = 0
y = 0
flag = 0
while len(d) != 0:
    if flag == 0:
        x += d.pop()
        flag = 1
    elif flag == 1:
        y += d.pop()
        flag = 0
print(x-y)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int, input().split()))
x.sort(reverse=True)
if n%2==1:
  x.append(0)
ans=0
for i in range(0,n,2):
  ans+=(x[i]-x[i+1])
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())
Z = list(map(int, input().split()))
Z.sort(reverse=True)
A = sum([Z[i] if i % 2 == 0 else 0 for i in range(N)])
B = sum([Z[i] if i % 2 == 1 else 0 for i in range(N)])
print(A-B)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for e, i in enumerate(a):
    if e % 2 != 0:
        ans += i
    else:
        ans -= i

print (abs(ans))

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
A = []
B = []
if n % 2 == 0:
    for i in range(0, n-1, 2):
        A.append(a[i])
    for j in range(1, n, 2):
        B.append(a[j])
else :
    for i in range(0, n, 2):
        A.append(a[i])
    for j in range(1, n-1, 2):
        B.append(a[j])

print(abs(sum(A)-sum(B)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B - Card Game for Two
N = int(input())
A = [int(a) for a in 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()))
sorted_card = sorted(card,reverse=True)
Alice = 0
Bob = 0

for i in range(N):
    if i == 0 or i % 2 == 0:
        Alice += sorted_card[i]
    else:
        Bob += sorted_card[i]

print(Alice - Bob)

Submission status: Accepted

Solution code:
n = int(input())
cards = map(int, input().split(' '))
sorted_cards = sorted(cards,reverse=True)

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

print(alice_sum - bob_sum)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    Alice = A[::-2]
    Bob = A[N-2::-2]
    print(sum(Alice)-sum(Bob))
resolve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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())
c=sorted([int(i) for i in input().split()])[::-1]
a=[]
b=[]
for i in range(n):
    if i%2==0:
        a.append(c[i])
    else:
        b.append(c[i])
print(sum(a)-sum(b))

Submission status: Accepted

Solution code:

n = int(input())
array = list(map(int, input().strip().split()))

alice_total = 0
bob_total = 0

for i in range(len(array)):
    if i % 2 == 0:
        max_value = max(array)
        max_index = array.index(max_value)
        alice_total += array.pop(max_index)
    else:
        max_value = max(array)
        max_index = array.index(max_value)
        bob_total += array.pop(max_index)

print(alice_total - bob_total)

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

alice = 0
bob = 0

a.sort(reverse=True)

turn = "alice"

for p in a :
    if turn == "alice" :
        alice = alice + p
        turn = "bob"
    elif turn == "bob" :
        bob = bob + p
        turn = "alice"

print(str(alice - bob))

Submission status: Accepted

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

Alice = 0
Bob = 0

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

print(Alice-Bob)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
#print(A)
Alice = []
Bob = []
for i in range(n):
    if i%2 != 0:
        Alice.append(A[i])
    else:
        Bob.append(A[i])
print(abs(sum(Alice) - sum(Bob)))

Submission status: Accepted

Solution code:
N=int(input())
a_input_list=input().split(' ')
a_num_list=[]
for a in a_input_list:
  a_num_list.append(int(a))

a_num_list.sort()
a_num_list.reverse()

bob=0
allice=0

counter=0
for a in a_num_list:
  if counter%2==0:
    allice+=a
  else:
    bob+=a
  counter+=1

print(allice-bob)

Submission status: Accepted

Solution code:
N=input()
a=list(map(int,input().split()))
a.sort(reverse = True)
Alice,Bob=0,0
while len(a) != 0:
  if len(a) != 0:
     Alice+=a.pop(0)
  if len(a) != 0:
     Bob += a.pop(0)
print(Alice-Bob)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = []
y = []

for i in range(n):
    a = sorted(a,reverse = True)
    x.append(a[0])
    y.append(a[1])
    a[0],a[1] = 0,0

print(sum(x)-sum(y))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = sorted(map(int, readline().split()))

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

Submission status: Accepted

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

alice = []
bob = []

a.sort(reverse=True)

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

ans = sum(alice) - sum(bob)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()])[::-1]
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)

Alice = 0
Bob = 0

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


print(Alice-Bob)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = list(map(int, readline().split()))
A.sort(reverse=True)

alice = bob = 0

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

print(alice - bob)

Submission status: Accepted

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

k = -1
sum1 = 0
sum2 = 0
for i in A:
  if k==-1:
    sum1+=i
  else:
    sum2+=i
  k*=-1
print(sum1 -sum2)

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 = [int(x) for x in 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 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()
l = inputIL()

l.sort(reverse=True)

A = l[::2]
B = l[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)
ali=0
bob=0

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

Submission status: Accepted

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