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

ans  =Alice - Bob
print(ans)

Submission status: Accepted

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

c.sort()

a=b=0
d=len(c)
for i in range(d):
    if i%2==0:
        a+=c[d-i-1]
    else:
        b+=c[d-i-1]

print(abs(a-b))

Submission status: Accepted

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

Alice = sum(a[0::2])
Bob = sum(a[1::2])

print(Alice-Bob)

Submission status: Accepted

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

Submission status: Accepted

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

b=sorted(a,reverse=True)

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

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

Submission status: Accepted

Solution code:
N = int(input())
arr = sorted(list(map(int, input().split())), reverse=True)
alice_total, bob_total = 0, 0

for i in range(len(arr)):
    if i % 2 == 0:
        alice_total += arr[i]
    else:
        bob_total += arr[i]
print(alice_total - bob_total)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
alice_score = []
bob_score = []
for i in range(N):
    if i % 2 == 0:
        alice_score.append(A.pop())
    else:
        bob_score.append(A.pop())
print(sum(alice_score) - sum(bob_score))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(abs(ans))

Submission status: Accepted

Solution code:
N=int(input())
A=0
B=0
for idx, a in enumerate(sorted(map(int, input().split()),reverse=True)):
    if (idx+1)%2:
        A+=a
    else:
        B+=a
print(A-B)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = sorted(map(int, input().split()), reverse=True)
sumA = 0
for x in range(len(a)):

    if x % 2 == 0:
        sumA += a[x]
    else:
        sumA -= a[x]
print(sumA)

Submission status: Accepted

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

print(A-B)

Submission status: Accepted

Solution code:
input()

data = [int(i) for i in input().split()]

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

Submission status: Accepted

Solution code:
input()
seq = sorted((int(x) for x in input().split()), reverse=True)
alice = sum(seq[::2])
bob = sum(seq[1::2])
print(alice - bob)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a=sorted(a,reverse=True)
turn=True
b,c=0,0
for i in range(n):
  if turn:
    b+=a[i]
    turn=False
  else:
    c+=a[i]
    turn=True
print(abs(b-c))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

lista.sort(reverse=True)

A=B=0

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

Submission status: Accepted

Solution code:
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

N = int(input())
a = readints()
# print(a)
aa = sorted(a, reverse=True)
# print(aa)
x = 0
for i in range(len(a)):
    if i % 2 == 0:
        x += aa[i]
    else:
        x -= aa[i]
print(x)

Submission status: Accepted

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

def puts(s): # 個人的にこのほうが解りやすいので。。。
    print(s)

def puti(i): # put integer
    print(str(i))

A.sort(reverse=True)

alice = 0
bob = 0

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

puti(alice - bob)

Submission status: Accepted

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

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

print(bob - alice)

Submission status: Accepted

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

a = sorted(a, reverse = True)
x = []
y = []
ans = 0
flg = 0
for i in a:
    if flg == 0:
        ans +=i
        flg = 1
    else:
        ans -=i
        flg = 0
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
alice = 0
bob = 0
a.sort()
while True:
    alice += max(a)
    a.pop()
    a.sort()
    if a == []:
        break
    bob += max(a)
    a.pop()
    if a == []:
        break
print(alice - bob)

Submission status: Accepted

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

Score = 0
for i, j in enumerate(a):
	if i & 1 == 0:
		Score += j
	else:
		Score -= j

print(Score)

Submission status: Accepted

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

x.sort(reverse=True)
alice = 0
bob = 0
for i, j in enumerate(x):
    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(reverse=True)

bob = []
alice = []

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()))
A.sort(reverse=True)
ans = 0
for i, a in enumerate(A):
  if i%2==0:
    ans += A[i]
  else:
    ans -= A[i]
print(ans)

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    A.sort()
    Alice, Bob = 0, 0
    for i in range(N):
        if i % 2 == 0: Alice += A[N-i-1]
        else: Bob += A[N-i-1]
    print(Alice - Bob)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

ai.sort(reverse=True)

A = sum(ai[::2])
B = sum(ai[1::2])

print(A-B)

Submission status: Accepted

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

if len(cards) % 2 == 0:
    alice = 0
    for i in range(int(N/2)):
        alice = alice + cards[2 * i]
    bob = 0
    for j in range(int(N/2)):
        bob = bob + cards[2 * j + 1]
else:
    alice = 0
    for i in range(int(N/2) + 1):
        alice = alice + cards[2 * i]
    bob = 0
    for j in range(int(N/2)):
        bob = bob + cards[2 * j + 1]
        
print(alice - bob)

Submission status: Accepted

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

score = 0
for i, j in enumerate(a_sort):
    if i % 2 == 0:
        score += j
    else:
        score -= j

print(score)

Submission status: Accepted

Solution code:
input()
cards = sorted([int(x) for x in input().split()], reverse = True)
alice_point = sum([x for i, x in enumerate(cards) if i % 2 == 0])
bob_point = sum([x for i, x in enumerate(cards) if i % 2 != 0])
print(alice_point - bob_point)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list((map(int, input().split())))
    a.sort()
    m = 0
    y = 0
    for i in reversed(range(n)):
        if len(a) % 2 == 0:
            if i % 2 != 0:
                m += a[i]
            else:
                y += a[i]
        else:
            if i % 2 == 0:
                m += a[i]
            else:
                y += a[i]
    print(m - y)
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    m = 0
    y = 0
    while len(a) > 0:
        m += max(a)
        a.remove(max(a))
        if len(a) == 0:
            break
        y += max(a)
        a.remove(max(a))
    ans = 0
    ans = m - y
    print(ans)
main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
Alice = 0
Bob = 0
ans = 0
while len(a) != 0:
    Alice += max(a)
    a.remove(max(a))
    if a:
        Bob += max(a)
        a.remove(max(a))
ans = Alice - Bob
print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    alice_score = 0
    bob_score = 0

    for loop,num in enumerate(a):
        if loop % 2 == 0:
            alice_score += num
        else: bob_score += num 

    print(alice_score - bob_score)

if __name__ == '__main__' :
    main()

Submission status: Accepted

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

A.sort(reverse=True)

Alice_point = sum(A[::2])
Bob_point = sum(A[1::2])

print(Alice_point - Bob_point)

Submission status: Accepted

Solution code:
N=int(input())
a=sorted(list(map(int,input().split(' '))),reverse=True)
Alice = sum([a[i] for i in range(0,N,2)])
Bob = sum([a[i] for i in range(1,N,2)])
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:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Alice = 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(map(int, input().split()), reverse=True)

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

Submission status: Accepted

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

alice_sum = sum(list_N[::2])
bob_sum = sum(list_N[1::2])

ans = alice_sum - bob_sum

print(ans)

Submission status: Accepted

Solution code:
# Author: cr4zjh0bp
# Created: Thu Mar 12 19:47:42 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

N = ni()
a = na()

alice, bob = 0, 0
a.sort()
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:
class CardGameforTwo:
    def __init__(self):
        self.alice_card_list = []
        self.alice_count = 0
        self.bob_card_list =[]
        self.bob_count = 0
        self.total_card_num = 0
        self.card_list = []
    
    def get_card(self, total_card_num, card_list):
        card_list.sort(reverse=True)
        card_num = 0
        for c in card_list:
            if card_num % 2 == 0:
                self.alice_card_list.append(c)
            else:
                self.bob_card_list.append(c)
            card_num +=1
        return self.alice_card_list, self.bob_card_list
    
    def count_result(self, a_card_list, b_card_list):
        for a in a_card_list:
            self.alice_count +=a
        for b in b_card_list:
            self.bob_count +=b
        result = self.alice_count - self.bob_count
        return result

if __name__ == '__main__':
    N = input()
    a =list(map(int, input().split()))
    cgt = CardGameforTwo()
    a_card_list, b_card_list=cgt.get_card(N, a)
    result = cgt.count_result(a_card_list, b_card_list)
    print(result)

Submission status: Accepted

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

a.sort(reverse=True)
al = True
al_s = 0
bo_s = 0

for i in a:
    if al:
        al_s = al_s + i
        al = False
    else:
        bo_s = bo_s + i
        al = True

print(al_s - bo_s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

A = 0
B = 0
while len(a) > 0:
  A += max(a)
  a.remove(max(a))
  if len(a) > 0:
    B += max(a)
    a.remove(max(a))
  
print(A-B)

Submission status: Accepted

Solution code:
firstint = int(input())
inputary = input()
listA= inputary.split()
numlist =[ int(x) for x in listA]
numlist.sort(reverse=True)
Alice = 0
Bob = 0
for index,elm in enumerate(numlist):
    if index % 2 == 0:
        Alice += int(numlist[index])
    else:
        Bob += int(numlist[index])

print(Alice - Bob)

Submission status: Accepted

Solution code:
def main():
    input()
    a = list(map(int, input().split()))
    a = sorted(a, key=lambda x: -x)
    print(sum(a[::2]) - sum(a[1::2]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

l1 = sorted(l, reverse = True)
Alice = 0
Bob = 0
for j in range(len(l)):
    if j % 2 == 0:
        Alice += l1[j]
    else:
        Bob += l1[j]
print(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(0, n, 2):
    alice += a_list[i]
for i in range(1, n, 2):
    bob += a_list[i]
    
result = alice - bob
print(result)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
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:
_ = input()
a = sorted(list(map(int,input().split())))[::-1]
print(sum(a[0::2])-sum(a[1::2]))

Submission status: Accepted

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

a.sort(reverse=True)

alice = sum([x for x in a[0::2]])
bob = sum([x for x in 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[0::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[0::2]) - sum(A[1::2]))

Submission status: Accepted

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

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

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


resolve()

Submission status: Accepted

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    A.sort(reverse=True)
    val=0
    for i in range(n):
        if i%2==0:
            val+=A[i]
        else:
            val-=A[i]

    print(val)



resolve()

Submission status: Accepted

Solution code:
N=int(input())

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

a.sort(reverse=True)
A=[]
B=[]

for i,k in enumerate(a):
    if i%2 == 0:
        A.append(a[i])
               
               
    elif i%2 == 1:
        B.append(a[i])
        
    
print(sum(A)-sum(B))

Submission status: Accepted

Solution code:
#input
N = int(input())
A = list(map(int, input().split()))
#A.sort() # 配列を小さい順に並び替え
A.sort(reverse = True) # 配列を大きい順に並び替え
#print(A)
alice = 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=input()
aa=list(map(int,input().split()))
aa.sort(reverse=True)

ab=[0]*2

i=0
for a in aa:
  ab[i%2]+=a
  i+=1

print(ab[0]-ab[1])

Submission status: Accepted

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

card.sort()
card.reverse()

p = [0,0]
for i in range(card_num):
  p[i%2] += card[i]
  
print(p[0]-p[1])

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()
a.reverse()
p = [0,0]
for i in range(N):
    p[i%2] += a[i]

print(p[0]-p[1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input()) #入力値
A = sorted(map(int, input().split()), reverse = True)
Bob=0
Alice=0
for i in range(0,N):
      if i % 2 == 0: # Bobが偶数なら実行
         Alice=Alice+int(A[i])
      else:
         Bob=Bob+int(A[i])
print(Alice-Bob)

Submission status: Accepted

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

    ascore = 0
    bscore = 0
    for i in range(N):
        if i%2 == 0:
            ascore += arr[i]
        else:
            bscore += arr[i]

    print(ascore - bscore)
    
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

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

t.sort(reverse=True)

fis = 0
sec = 0

for i in range(n):
    if i%2==0:
        fis += t[i]
    else:
        sec += t[i]
print(fis-sec)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc088/tasks/abc088_b

def main():
    n = int(input())
    i = list(map(int,input().split()))
    # j = list(map(int,input().split()))

    i.sort(reverse=True)
    # print(i)

    # print(i[::2])
    # print(i[1::2])
    print(sum(i[::2]) - sum(i[1::2]))

main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
i = 0
Alice = []
Bob = []
while i < n:
    if a == []:
        break
    else:
        Alice.append(max(a))
        a.remove(max(a))
    if a == []:
        break
    else:
        Bob.append(max(a))
        a.remove(max(a))
    i += 1
print(abs(sum(Alice) - sum(Bob)))

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:

def Card_Game(n , al):

    al.sort(reverse=True)

    Alice = al[0::2]
    Bob = al[1::2]

    ans = sum(Alice) - sum(Bob)

    return ans

def main():
    n = int(input())
    al = list(map(int , input().split()))
    print(Card_Game(n , al))

if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

alice_list = a_sorted[::2]
bob_list = a_sorted[1::2]

print(sum(alice_list) - sum(bob_list))

Submission status: Accepted

Solution code:
N = input()
a = list(map(int, input().split()))
a_sorted = sorted(a, reverse=True)
is_alice = True
a_score = 0
b_score = 0
for num in a_sorted:
    if is_alice == True:
        a_score += num
        is_alice = False
    else:
        b_score += num
        is_alice = True
        
print(a_score - b_score)

Submission status: Accepted

Solution code:
#ABC088

m = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
p = 0
q = 0
for i in range(len(a)//2):
    p += a[2 * i]
    q += a[2 * i + 1]

if len(a) % 2 != 0:
    p += a[-1]

print(p-q)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a = []
b = []
l.sort(reverse=True)
for i, r in enumerate(l, start=1):
    if i % 2 == 1:
        a.append(r)
    else:
        b.append(r)
print(sum(a) - sum(b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC 088 B
import numpy as np

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

a = np.array(a)
a_sort = np.sort(a)

ans = np.sum(a_sort[-1::-2]) - np.sum(a_sort[-2::-2])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

a.sort(reverse=True)

Alice = 0
Bob = 0
i = 1

for j in a:
    if i % 2 == 1:
        Alice += j
    else:
        Bob += j

    i += 1

print(Alice - Bob)

Submission status: Accepted

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

if n % 2:
    a.append(0)
aa = 0
bb = 0
for i in range(0,len(a),2):
    aa += a[i]
    bb += a[i+1]

print(aa-bb)

Submission status: Accepted

Solution code:
## coding: UTF-8
N = int(input())
A = [int(x) for x in input().split()]

#print(N)
#print(A)
A.sort(reverse=True) #大きい順に並べる
#print(A)

Alice = []
Bob = []

counter = 0

while True:
    if(len(A) == 0):
        break #リストの要素が全部取得されたらループを消す

    if(counter % 2 == 0): #first,third,...
        #x = A.pop(0)
        Alice.append(A.pop(0))
        counter += 1
    else:
        Bob.append(A.pop(0))
        counter += 1
    
#print(Alice)
#print(sum(Alice))
#print(Bob)
#print(sum(Bob))
print(sum(Alice) - sum(Bob))

Submission status: Accepted

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

alice = []
bob = []

for i in range(n):
    if not a:
        break
    max_num = max(a)
    a.remove(max_num)
    alice.append(max_num)
    if not a:
        break
    max_num = max(a)
    a.remove(max_num)
    bob.append(max_num)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 標準入力
num = int(input())
data = list(map(int, input().split()))

# 初期化
alice = 0
bob = 0

# 降順にソート
data = sorted(data, reverse=True)

for i in range(num):
    if i % 2 == 0:
        alice += int(data[i])
    else:
        bob += int(data[i])

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

a.sort(reverse=True)

res= sum(a[0::2])-sum(a[1::2])

print(res)

Submission status: Accepted

Solution code:
#088_B
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[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:
N = int(input())
a = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
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

print(alice - bob)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
ans=0
for i in range(n):
  ans+=a[n-1-i]*(-1)**i
print(int(ans))