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:
from sys import stdin

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

a.sort(reverse=True)

Alice = 0
for i in range(0,len(a),2):
    Alice += a[i]

Bob = sum(a)-Alice

print(Alice - Bob)

Submission status: Accepted

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

bob = 0
alice = 0

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

Submission status: Accepted

Solution code:
# template by 3xC and starkizard.
# contributors: 

#####################################################################################
from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""


# from bisect import bisect_left, bisect_right, insort
# from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
# from copy import deepcopy
# from decimal import *
# import re
# import operator

#####################################################################################
# this enables you to write python3 code with PyPy2 (Python 2)
if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

#####################################################################################

"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""
# import threading
# threading.stack_size(1<<27)
# sys.setrecursionlimit(10000

def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    # Comment code out when you don't need inverse factorial or vice versa
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod

    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): # math.gcd is slower
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def check_sorted(a):
    ''' returns True/False '''
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return False
    return True
def ceil(n, k=1): return n // k + (n % k != 0) #returns math.ceil but protecting against floating inconsistencies
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) #inputs integer
def mi(): return map(int, input().split()) # inputting space seperated variables for example x,y,z
def li(): return list(map(int, input().split())) #inputting a space seperated list of integers
def lw(): return input().split() #inputting a space seperated list of strings
def lcm(a, b): return abs(a * b) // gcd(a, b) #returns LCM of two arguments
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) #For printing an iterable with seperator sep as optional second argument (default : " "), ending character (default: "\n") as optional third
def dd(): return defaultdict(int) #returns a dictionary with values defaulted to 0
def ddl(): return defaultdict(list) #returns a dictionary with values defaulted to []
def write(s): return sys.stdout.write(s)












###################################################################
def main():
    #CODE GOES HERE:
    n=ii()
    a=li()
    a.sort(reverse=True)
    x=[]
    y=[]
    for i in range(n):
        if i%2==0:
            x.append(a[i])
        else:
            y.append(a[i])
    print(abs(sum(x)-sum(y)))






















""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

""" main function"""

if __name__ == '__main__':
    main()
    # threading.Thread(target=main).start()

Submission status: Accepted

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


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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

sl = sorted(l, reverse = True)

A = []
B = []

for _ in range(len(l)):
  if _%2 == 0:
    A.append(sl[_])
  else:
    B.append(sl[_])

gap = sum(A) - sum(B)

print(gap)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
_ = input()
cards = map(int, input().split())
cards = sorted(cards)[::-1]

a = sum(cards[0::2])
b = sum(cards[1::2])

print(a-b)

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(0, len(a)):
    if i % 2 != 0:
        bob += a_1[i]
    if i % 2 == 0:
        alice += a_1[i]
        
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:
input()
a = sorted(map(int, input().split()))[::-1]
print(sum(a[::2])-sum(a[1::2]))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
Alice = 0
Bob = 0
for i in range(0, len(a), 2):
    Alice += a[i]
    if i + 1 < len(a):
        Bob += a[i + 1]
print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n)[::2]:
    k += a[i]

for i in range(n)[1::2]:
    l += a[i]

print(k - l)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
# coding-utf8 #

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

alice_sum = 0
bob_sum = 0

num_list.sort(reverse=True)

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

print(alice_sum - bob_sum)

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

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

Submission status: Accepted

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

#Alice,Bob
a=[]
b=[]

for i in range(n):
    if i%2==0:
        a.append(s[i])
    else:
        b.append(s[i])
        
print(sum(a)-sum(b))

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N = int(input())
    A = [int(x) for x in input().split(" ")]
    A.sort(reverse=True)
    al = 0
    bob = 0
    for i, a in enumerate(A):
        if i % 2 == 0:
            al += a
        else:
            bob += a
    print(al - bob)

Submission status: Accepted

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

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

print(alice - bob)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations
import math


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.sort()
A = A[::-1]
alice = 0
bob = 0
flag = 0
for i in A:

    if flag % 2 == 0:
        alice += i
    else:
        bob += i
    flag += 1
print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(A-B)

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()))
a.sort(key=int,reverse=True)
A,B=[],[]
for i in a:
    if len(A)==len(B): A.append(i)
    else : B.append(i)
print(sum(A)-sum(B))

Submission status: Accepted

Solution code:

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

alice_point = 0
bob_point = 0

def pick_card(card_list):
    # print(card_list)
    max = 0
    max_index = 0
    for i in range(card_list.__len__()):
        # print('-------', i)
        if card_list[i] > max:
            # print('@', i, ':', max, '<', card_list[i])
            max = card_list[i]
            max_index = i
    
    del card_list[max_index]

    # print('----', card_list)

    return max, card_list

def sort_card(card_list: list):
    return sorted(card_list, reverse=True)

turn = 0
sorted_list = sort_card(card_list)
while turn < n:
    # print('--', turn)
    if turn % 2 == 0:
        # alice_get, remain_list = pick_card(card_list)
        # alice_point += alice_get
        alice_point += sorted_list.pop(0)
    else:
        # bob_get, remain_list = pick_card(card_list)
        # bob_point += bob_get
        bob_point += sorted_list.pop(0)

    # card_list = remain_list
    # print(alice_point, bob_point, sorted_list)

    turn += 1

print(alice_point - bob_point)

Submission status: Accepted

Solution code:

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

alice_point = 0
bob_point = 0

def pick_card(card_list):
    # print(card_list)
    max = 0
    max_index = 0
    for i in range(card_list.__len__()):
        # print('-------', i)
        if card_list[i] > max:
            # print('@', i, ':', max, '<', card_list[i])
            max = card_list[i]
            max_index = i
    
    del card_list[max_index]

    # print('----', card_list)

    return max, card_list

turn = 0
while turn < n:
    # print('--', turn)
    remain_list = []
    if turn % 2 == 0:
        alice_get, remain_list = pick_card(card_list)
        alice_point += alice_get
    else:
        bob_get, remain_list = pick_card(card_list)
        bob_point += bob_get

    card_list = remain_list
    # print(alice_point, bob_point, card_list)

    turn += 1

print(alice_point - bob_point)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
a = sorted(map(int, input().split()),reverse=True)

pA=[]
pB=[]
  
for i in range(N):
  m=a[i]
  if i%2==0:
    pA.append(m)
  else:
    pB.append(m)
print(sum(pA)-sum(pB))

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
a = list(map(int, input().split())) 

pA=[]
pB=[]
  
for i in range(N):
  m=max(a)
  if i%2==0:
    pA.append(m)
  else:
    pB.append(m)
  a.remove(m)
print(sum(pA)-sum(pB))

Submission status: Accepted

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

def main():
    n = int(input())
    a = sorted(list(map(int, input().split())), reverse=True)
    ans = 0
    j = 1
    for i in range(n):
        ans += a[i] * j
        j *= -1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

a.sort()

num = len(a)-1
alice, bob = 0, 0

while num >= 0:
  alice += a[num]
  num -= 1
  if num < 0:
    break
  bob += a[num]
  num -= 1
  
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, N, 2):
    Alice += a[i]

Bob = sum(a) - Alice
ans = Alice - Bob

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#! env python
# -*- coding: utf-8 -*-

import os
import sys


# ac_py.main
# Date: 2020/06/08
# Filename: main 
# Author: acto_mini

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a_list = sorted([int(s) for s in input().split()], reverse=True)
sum_list = [0, 0]
for i in range(n):
    sum_list[i % 2] += a_list[i]
print(sum_list[0] - sum_list[1])

Submission status: Accepted

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

flag = 0
Alice = 0
Bob = 0
for a in A:
    if flag==0:
        Alice += a
        flag = 1
    elif flag==1:
        Bob += a
        flag = 0
print(abs(Alice-Bob))

Submission status: Accepted

Solution code:
num = int(input())
st = list(map(int,input().split()))
flag = True
all1 = 0
all2 = 0
for i in range(num):
  if flag == True:
    sum1 = max(st)
    st.remove(sum1)
    all1 = all1 + sum1
    flag = False
  else:
    sum1 = max(st)
    st.remove(sum1)
    all2 = all2 + sum1
    flag = True

print(all1-all2)

Submission status: Accepted

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

alice = 0
bob = 0

while 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()))
a = list(reversed(sorted(a)))
A = sum(a[::2])
B = sum(a[1::2])
print(A-B)

Submission status: Accepted

Solution code:

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

A = sorted(A, reverse=True)

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

Submission status: Accepted

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

N = int(input())
a = sorted([int(i) for i in input().split()], reverse=True)

bob_filter = [i % 2 for i in range(len(a))]
alice_filter = [not i for i in bob_filter]
result = sum(list(itertools.compress(a, alice_filter))) \
         - sum(list(itertools.compress(a, bob_filter)))
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A =[i for i in map(int,input().split())]
A = sorted(A,reverse=True)
Alice = 0
Bob = 0
while len(A) != 0:
    Alice += int(A.pop(0))
    if len(A) == 0:
        break
    else:
        Bob += int(A.pop(0))

print(Alice - Bob)

Submission status: Accepted

Solution code:
n = int(input())
array = input().split()
for i in range(n):
  array[i] = int(array[i])
alice = 0
bob = 0
array.sort(reverse=True)
for i in range(n):
  if(i%2==0):
    alice += array[i]
  else:
    bob += array[i]
z = alice - bob
print(z)

Submission status: Accepted

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

x = sorted(a)[::-1]
sum_al = 0
sum_bb = 0
for i in range(N):
    if i % 2 ==0:
        sum_al += x[i]
    else:
        sum_bb += x[i]

print(sum_al - sum_bb)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
i = len(a) - 1
fl = True
sumal = 0
while(i >= 0):
    if fl:
        sumal += a[i]
        fl = False
    else:
        sumal -= a[i]
        fl = True
    i -= 1
print(sumal)

Submission status: Accepted

Solution code:
N=int(input())
an=map(int,input().split())
Cards=[]
for a in an:
    Cards.append(int(a))
SortedCards=sorted(Cards,reverse=True)
AliceCards=SortedCards[0::2]
BobsCards=SortedCards[1::2]
print(sum(AliceCards)-sum(BobsCards))

Submission status: Accepted

Solution code:
N = int(input())
P1 = 0
P2 = 0

arr = list(map(int, input().strip().split()))
arr = sorted(arr)

for i in range(0,len(arr)):
  if i%2 == 0:
    P1 = P1+arr[i]
  elif i%2 ==1:
    P2 = P2+arr[i]
print(abs(P2-P1))

Submission status: Accepted

Solution code:
# B - Card Game for Two

N = int(input())
A = list(int(a) for a in input().split())
A.sort(reverse=True)

alice = 0
bob = 0

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

print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
s = sorted(a, reverse=True)
A = 0
B = 0
for i in range(N):
    if not i % 2:
        A += s[i]
    else:
        B += s[i]
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())
alise=0
bob=0
a_list=list(map(int,input().split()))
a_sort=sorted(a_list)[::-1]
a_sort.append(0)
for i in range(N//2+N%2):
    alise+=a_sort.pop(0)
    bob+=a_sort.pop(0)
print(alise-bob)

Submission status: Accepted

Solution code:
N=int(input())
alise=0
bob=0
a_list=list(map(int,input().split()))
a_sort=sorted(a_list)
for i in range(N,0,-2):
    alise+=a_sort[i-1]
for i in range(N-1,0,-2):
    bob+=a_sort[i-1]
print(alise-bob)

Submission status: Accepted

Solution code:
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N = input_number()
    a = input_number_list()
    a.sort(reverse=True)
    alice = sum(a[::2])
    bob = sum(a[1::2])
    print(alice - bob)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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(N):
    if i % 2 == 0:
        alice += a[i]
    else:
        bob += a[i]

print(alice - bob)

Submission status: Accepted

Solution code:
def main():
    target_num = input()
    target_list = list(map(int, input().split()))

    target_list.sort(reverse=True)

    result_a = 0
    result_b = 0
    a_flg = True
    for target in target_list:
        if a_flg:
            result_a += int(target)
            a_flg = False
        else:
            result_b += int(target)
            a_flg = True

    print(result_a - result_b)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a_list.sort(reverse=True)
Asum = 0
Bsum = 0

for i in range(0,N,2):
    Asum += a_list[i]

for i in range(1,N,2):
    Bsum += a_list[i]

print(Asum-Bsum)

Submission status: Accepted

Solution code:
n = input()
a = [int(i) for i in input().split()]
alice = []
bob = []
for i in range(int(n)):
    try:
        alice.append(max(a))
        a.remove(max(a))
        bob.append(max(a))
        a.remove(max(a))
    except:
        pass
print(sum(alice) - sum(bob))

Submission status: Accepted

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

tmp = []
ttmp = []

list.sort(a,reverse=True)

for i in range(1,n+1):
    if i%2==1:
        tmp.append(a.pop(0))
    if i%2==0:
        ttmp.append(a.pop(0))
        # ttmp = a.pop(0)

print(sum(tmp)-sum(ttmp))

Submission status: Accepted

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

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

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())
x=list(map(int,input().split()))
a=0
b=0
for i in range(n//2):
  a+=max(x)
  x.remove(max(x))
  b+=max(x)
  x.remove(max(x))

if n%2:
  a+=x[0]
dif=a-b
print(dif)

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:
def resolve():
    N = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    Alice = []
    Bob = []
    for i, j in enumerate(a):
        if i % 2 == 0:
            Alice.append(j)
        else:
            Bob.append(j)
    print(sum(Alice) - sum(Bob))
    return

resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,*A=map(int,open(0).read().split())
A.sort(reverse=True)
print(sum(A[::2])-sum(A[1::2]))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

def main():
    n = int(input())
    A = list(map(int, input().split()))

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Alics_score = 0
Bob_score = 0

for _ in range(int(n/2)+1):
    if As == []:
        break
    Alics_score += max(As)
    As.remove(max(As))
    if As == []:
        break
    Bob_score += max(As)
    As.remove(max(As))

print(Alics_score - Bob_score)

Submission status: Accepted

Solution code:
N = int(input())
x = list(map(int, input().split()))
A = [0] * N
B = [0] * N
x.sort()
x.reverse()
for i in range(N):
    if i % 2 == 0:
        A[i] = x[i]
    else:
        B[i] = x[i]
print(sum(A) - sum(B))