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:
def main():
	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)


if __name__ == '__main__':
	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
var = list(map(int, input().split()))
var_max = 0
alice = 0
bob = 0
for y in range(n):
    var_max = 0
    for x in var:
        if(var_max <= x):
            var_max = x
    var.remove(var_max)
    if(y % 2 == 0):
        alice += var_max
    else:
        bob += var_max
print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
line = list(map(int, input().split()))
line.sort(reverse=True)
ans = 0
i = 0
while line:
    p = line.pop(0)
    if i % 2 == 0:
        ans += p
    else:
        ans -= p
    i += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
al, bo = [], []
for i in range(n):
	if i % 2 == 0:
		al.append(max(a))
		a.remove(max(a))
	else:
		bo.append(max(a))
		a.remove(max(a))
print(sum(al)-sum(bo))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
al, bo = [], []
for i in range(n):
	if i % 2 == 0:
		al.append(max(a))
		a.remove(max(a))
	elif i % 2 == 1:
		bo.append(max(a))
		a.remove(max(a))
print(sum(al)-sum(bo))

Submission status: Accepted

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

dif = 0
sgn = '+'
for a in A:
    if sgn == '+':
        sgn = '-'
        dif += a
    else:
        sgn = '+'
        dif -= a

print(dif)

Submission status: Accepted

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

alice = 0
bob = 0
count = 0

a.sort(reverse = True)

for i in a:
    if count%2 == 0:
        alice += i
    else:
        bob += i
    count += 1

print(alice - bob)

Submission status: Accepted

Solution code:
n=int(input())

a=list(map(int, input().split()))
Alice=[]
Bob=[]
a.sort(reverse=True)

for i in range(0,n,2):
    Alice.append(a[i])
    if i!=n-1:
        Bob.append(a[i+1])
    
d=sum(Alice)-sum(Bob)
print(d)

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())
listA=list(map(int,input().split()))
listA.sort(reverse=True)
a=0
b=0
for i in range(N):
  if i%2==0:
    a+=listA[i]
  else:
    b+=listA[i]
print(a-b)

Submission status: Accepted

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

Submission status: Accepted

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

allis = 0
bob = 0

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

print(allis-bob)

Submission status: Accepted

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

n = int(input())
#tmp = input()
tmp = input().split()
#(lambda a:int(a))(tmp)
hoge = list(map(lambda a: int(a), tmp))
hoge.sort()
hoge.reverse()

sum_al=0
sum_bo=0
for i,j in enumerate(hoge):
	if (i%2 == 0):
		sum_al+=j
	else:
		sum_bo+=j
print(sum_al-sum_bo)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    a_list = list(map(int, input().split()))

    a_list = sorted(a_list, reverse=True)

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

Submission status: Accepted

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]
lst.sort()
lst = lst[::-1]
sum_a = 0
sum_b = 0
for i in range(n):
    if i%2==0:
        sum_a += lst[i]
    else:
        sum_b += lst[i]
print(sum_a - sum_b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
s=sum(a)
p=0
for i in range(0,len(a),2):
  p+=a[i]
print(p*2-s)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
# Aliceの点数
point_A = 0
# Bobの点数
point_B = 0
N = int(input())
A = np.array([int(i) for i in input().split()])
A = np.sort(A)
for j in range(N):
    if j % 2 == 0:
        point_A += A[N - 1 - j]
    else:
        point_B += A[N - 1 - j]
print("{}".format(point_A - point_B))

Submission status: Accepted

Solution code:
n=int(input())

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

for i in range(n):
    for j in range(n):
        if a[i] < a[j]:
            work = a[i]
            a[i] = a[j]
            a[j] = work

s1 = 0
s2 = 0

for i in range(0,n,2):
    s1 += a[i]

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

output = s2-s1

if output < 0:
    output *= -1

print(output)

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
n=int(input())

nums=list(map(int,input().split()))
nums.sort(reverse=True)
#print(nums)

alice=[]
bob=[]

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

    else:
        bob.append(nums[i])

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

Submission status: Accepted

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

A, B = 0, 0

a.sort()
a.reverse()
for i, j in enumerate(a):
    if i % 2 == 0:
        A += j
    else:
        B += j
        
print(A - B)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
length = int(input())
cards = list(map(int,input().split()))
sorted_cards = sorted(cards, reverse=True)
Alice_sum = sum(sorted_cards[0::2])
Bob_sum = sum(sorted_cards[1::2])
print(Alice_sum-Bob_sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = [int(aa) for aa in input().split()]
a.sort(reverse = True)
A = []
B = []
while len(a) > 0:
  A.append(a[0])
  a.pop(0)
  if len(a) == 0:
    break
  B.append(a[0])
  a.pop(0)
ans = sum(A) - sum(B)
print(ans)

Submission status: Accepted

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

a.sort()


alice = 0
bob = 0
flg = 0

while(len(a)>0):
    if flg == 0:
        alice += a.pop()
    elif flg ==1:
        bob += a.pop()
    flg = not(flg)

print(alice-bob)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
cnt = 0
sum1 = 0
sum2 = 0
for i in range(n):
	if cnt % 2 == 0:
		sum1 += a[i]
	else:
		sum2 += a[i]
	cnt += 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(n):
    if i%2 == 0:
        alice += A[i]
    else:
        bob += A[i]
print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a_p = 0
b_p = 0

for i in range(N):
    m = max(alist)
    if i%2 == 0:
        a_p += m
        alist[alist.index(m)] = 0
    else:
        b_p += m
        alist[alist.index(m)] = 0
print(a_p - b_p)

Submission status: Accepted

Solution code:
N = int(input())

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

a_list = sorted(a_list)[::-1]

al = sum([a for i,a in enumerate(a_list) if i%2==0])
bo = sum([a for i,a in enumerate(a_list) if i%2==1])

print(al-bo)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

n = int(input())

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

a.sort(reverse=True)

alice = 0
bob = 0

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

ans = alice - bob

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
Alice = 0
Bob = 0

for i in range(N):
  max_val = max(a)
  max_idx = a.index(max_val)
  
  if i % 2 == 0:
    Alice += max_val
  else:
    Bob += max_val
  del a[max_idx]

print(Alice - Bob)

Submission status: Accepted

Solution code:
n = int(input())
num_list =list(map(int,input().split()))
num_list.sort(reverse=True)
bob = 0
alice = 0
for i,num in enumerate(num_list):
    if i%2 == 0:
        alice += num
    else:
        bob += num
print(alice-bob)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())),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:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
A = nl()

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:
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]

N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse=True)
a = sum(A[0::2])
b = sum(A[1::2])

print(a - b)

Submission status: Accepted

Solution code:
from sys import stdin

n = stdin.readline().rstrip()
arr = [int(x) for x in stdin.readline().rstrip().split()]

alice_score = 0
bob_score = 0

for i in range(len(arr)):
    max_num = max(arr)
    if(i%2!=0):
        
        alice_score += max_num
        arr.remove(max_num)
    else:
        bob_score += max_num
        arr.remove(max_num)

print(abs(alice_score - bob_score))

Submission status: Accepted

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


abc()

Submission status: Accepted

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

for i in range(N):
    m = max(A)
    A.remove(m)
    if i % 2 == 0:
        alice += m
    else:
        bob += m
print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a_list = [int(i) for i in input().split()]
a_list.sort(reverse=True)
alice = sum(a_list[0::2])
bob = sum(a_list[1::2])
print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

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

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):
  ans += a[i] * ((-1) ** i)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
LIST = list(map(int, input().split()))
LIST.sort()
Bob = 0
Alice = 0

while True:
    if len(LIST) == 0:
        break
    Alice = Alice + LIST.pop()
    if len(LIST) == 0:
        break
    Bob = Bob + LIST.pop()

print(Alice - Bob)

Submission status: Accepted

Solution code:
n = input()
list_num = [int(num) for num in input().split()]
 
list_num.sort(reverse=True)
a = sum(list_num[0::2])
b = sum(list_num[1::2])
 
print(a-b)

Submission status: Accepted

Solution code:
N=int(input())
cardmap=map(int,input().split())
card=list(cardmap)
card.sort(reverse=True)
Alist=card[0::2]
Blist=card[1::2]
Asum=sum(Alist)
Bsum=sum(Blist)
print(Asum-Bsum)

Submission status: Accepted

Solution code:
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    alist = list(map(int, input().split()))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
cards = [int(x) for x in input().split()]
ALICE = 0
BOB = 0
while cards:
  temp = max(cards)
  cards.remove(temp)
  ALICE+=temp
  if not(cards):
    break
  temp = max(cards)
  cards.remove(temp)
  BOB+=temp

print(ALICE - BOB)

Submission status: Accepted

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

input_lis.sort(reverse=True)
a,b = 0,0
for i in range(len(input_lis)):
    if i % 2 == 0:
        a += input_lis[i]
    else:
        b += input_lis[i]
        
print(a-b)

Submission status: Accepted

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

Submission status: Accepted

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

from math import *
from itertools import *
from collections import *
from bisect import *


if __name__ == '__main__':
    input()
    lst = [int(x) for x in input().split()]
    lst.sort(reverse=True)
    n = sum(lst)
    na = sum(lst[::2])
    print(na-n+na)

Submission status: Accepted

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

print(alice - bob)

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())

list = input().split(" ")
num_list = []

for num in list:
    num_list.append(int(num))

num_list.sort(reverse=True)

alice = 0
bob = 0

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

print(alice - bob)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
alice = []
bob = []
while len(a) >= 1:
    alice.append(a.pop())
    if len(a) >= 1:
        bob.append(a.pop())
print(sum(alice) - sum(bob))

Submission status: Accepted

Solution code:
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

# N = int(sys.stdin.readline())
# S = sys.stdin.readline().rstrip().split()
#
# if len(set(S)) == 3:
#     print('Three')
# else:
#     print('Four')

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
ac = 0
bc = 0

A.sort(reverse=True)
for i, a in enumerate(A):
    if i % 2 == 0:
        ac += a
    else:
        bc += a
print(ac - bc)

Submission status: Accepted

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

n = int(input())
a = sorted(list(map(int, input().split())), 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())
al=list(map(int,input().split()))
al.sort(reverse=True)
alice=0
bob=0
flg=True
for a in al:
    if flg:
        alice+=a
    else:
        bob+=a
    flg=False if flg else True
print(alice-bob)

Submission status: Accepted

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

coef = 1
score = 0
while A:
  score += A.pop() * coef
  coef *= (-1)

print(score)

Submission status: Accepted

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

Alice=0
Bob=0
n=1

while n<=N:
  if n%2==1:
    Alice=Alice+max(A)
    A.remove(max(A))
    n=n+1
  else:
    Bob=Bob+max(A)
    A.remove(max(A))
    n=n+1
print(Alice-Bob)

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:
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    a.sort(reverse=True)
    print(sum(a[0::2])-sum(a[1::2]))
    return


# Generated by 1.1.4 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:
n=int(input())
cards=sorted(list(map(int,input().split())),reverse=True)
Alice=sum(cards[::2])
Bib=sum(cards[1::2])
print(Alice-Bib)

Submission status: Accepted

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

cards.sort()
cards.reverse()

p1 = 0
p2 = 0

for i in range(N):
    if i%2==0:
        p1+=cards[i]
    else:
        p2 += cards[i]

print(p1-p2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))
list.sort(li, reverse = True)
switch = 1
Alice = 0
Bob = 0
for i in li:
    if switch == 1:
        Alice += i
        switch = 0
    else:
        Bob += i
        switch = 1
print(Alice - Bob)

Submission status: Accepted

Solution code:
import re  # 正規表現, findall('正規表現', 文字列), search('正規表現', 文字列)
import sys # プログラム終了：sys.exit()
# sys.setrecursionlimit(10**6) # 再帰呼び出しの上限を上げる

def i_input(): return int(input())
def s_input(): return map(int,input().split())
def l_input(): return list(map(int, input().split()))
# 文字列のまま受け取りたいときはinput()

N = i_input()
A = l_input()

alice = 0
bob = 0

for i in range(N):
    biggest = max(A)
    if i % 2 == 0:
        alice += biggest
    else:
        bob += biggest
    A.remove(biggest)

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    a = list(int(_) for _ in input().split())
    a.sort()
    a = a[::-1]
    ans = 0
    for i in range(N):
        if i % 2 == 0:
            ans += a[i]
        else:
            ans -= a[i]
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a_nums = []
tmp = input().split()
for i in range(n):
    a_nums.append(int(tmp[i]))

a_nums.sort(reverse=True)

num_sum = 0
for i in range(n):
    if i%2 == 0:
        num_sum = num_sum+a_nums[i]
    else:
        pass


sum_up = 0
for i in range(n):
    sum_up = sum_up + a_nums[i]

print(num_sum - sum_up + num_sum)

Submission status: Accepted

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

a.sort(reverse = True)
L = [0, 0]
f = 0
for i in a:
  L[f] += i
  f = 1 - f

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

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())
s=list(map(int,input().split()))
s.sort()
j=A=B=0
for i in s[::-1]:
    if j==0:A+=i
    else:B+=i
    j=1-j
print(A-B)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
Alice = 0
Bob = 0
card = 0
for i in range(N):
    if A == []:
        break
    card = max(A)
    if card == 0:
        break
    else:
        Alice += card
        A.remove(card)
    if A == []:
        break
    card = max(A)
    if card == 0:
        break
    else:
      Bob += card
      A.remove(card)
print(Alice-Bob)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split(' ')))
    A.sort()
    Alice = 0
    Bob = 0
    turn = True
    for _ in range(N):
        if turn:
            Alice += A.pop()
            turn = False
        else:
            Bob += A.pop()
            turn = True
            
    print(abs(Alice - Bob))

Submission status: Accepted

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

a.sort(reverse=True)

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

Submission status: Accepted

Solution code:
N = int(input())
alice = 0
bob = 0
a = [int(i) for i in input().split()] 
while len(a) != 0:
    alice += max(a)
    a.remove(max(a))
    while len(a) != 0:
        bob += max(a)
        a.remove(max(a))
        break
print(alice - bob)

Submission status: Accepted

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

lst.sort(reverse = True)

A = 0
for i in range(0,N,2):
  A += lst[i]
B = 0
for j in range(1,N,2):
  B += lst[j]
print (A-B)

Submission status: Accepted

Solution code:

N = input()

lst_A = input().split()

A_sum = 0
B_sum = 0

for i in range(len(lst_A)):
    lst_A[i] = int(lst_A[i])

lst_A.append(-1)

lst_A.sort(reverse=True)

while 1:
    if lst_A[0] == -1:
        break
    A_sum += lst_A[0]
    del lst_A[0]
    if lst_A[0] == -1:
        break
    B_sum += lst_A[0]
    del lst_A[0]

ans = A_sum - B_sum
print(ans)

Submission status: Accepted

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

a.sort(reverse=True)

ans1 = a[::2]
ans2 = a[1::2]

print(sum(ans1)-sum(ans2))

Submission status: Accepted

Solution code:
def solve(A):
    A = sorted(A, reverse=True)
    return sum(A[::2])-sum(A[1::2])

N = int(input())

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

print(A-B)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
x=0
y=0
for i,a in enumerate(A):
    if i%2==0:
        x+=a
    else:
        y+=a
print(x-y)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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())
Als = []

x = input().split(" ")

for i in range(N):
    Als.append(int(x[i]))

Als.sort(reverse = False)

Alice = 0
Bob = 0


for i in range(N):
    now = Als.pop()
    if i%2 == 0:
        Alice += now
    else:
        Bob += now

print(Alice - Bob)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
alice = 0
bob = 0
n = 0
while len(a) > 0:
    if n == 0:
        alice += a.pop()
        n = 1
    else:
        bob += a.pop()
        n = 0
print(alice - bob)

Submission status: Accepted

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

even = sum(a[0::2])
odd = sum(a[1::2])
print(abs(even - odd))

Submission status: Accepted

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

alice = 0
bob = 0

a.sort(reverse=True)

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

Submission status: Accepted

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

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

print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    A_list = list(map(int, input().split()))

    A_list = sorted(A_list, reverse=True)

    odd_A_list = A_list[::2]
    even_A_list = A_list[1::2]

    print(sum(odd_A_list)-sum(even_A_list))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a.sort(reverse=True)

a_ = []
b_ = []
for i,j in enumerate(a):
    if i%2 == 0:
        a_.append(j)
    else:
        b_.append(j)
        
print(sum(a_)-sum(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]))