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: Wrong Answer

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

def heap_sort(arr_ref):
    def swap(arr, a, b):
        tmp = arr[a]
        arr[a] = arr[b]
        arr[b] = tmp
    arr = arr_ref
    arr_sorted = []
    if(len(arr) == 1):
        arr_sorted = arr
    elif(len(arr) == 2):
        if(len(arr) <= 2):
            if(arr[0] < arr[1]):
                swap(arr, 0, 1)
            arr_sorted = arr
    else:
        while(True):
            while(True):
                flag_swap = True
                for i in range(int(len(arr)/2)): #配列の一番最後の根まで
                    if((arr[i] < arr[i*2]) and (arr[i] < arr[i*2 + 1])):
                        if(arr[i*2] > arr[i*2 + 1]):
                            swap(arr, i, i*2)
                        else:
                            swap(arr, i, i*2 + 1)
                    elif(arr[i] < arr[i*2]):
                        swap(arr, i, i*2)
                    elif(arr[i] < arr[i*2 + 1]):
                        swap(arr, i, i*2 + 1)
                    else:
                        flag_swap = False
                if(not flag_swap):
                    break
            arr_sorted.append(arr[0])
            arr[0] = arr[-1]
            del arr[-1]
            if(len(arr) <= 2):
                if(arr[0] < arr[1]):
                    swap(arr, 0, 1)
                arr_sorted.extend(arr)
                break
    arr_sorted.reverse()
    return arr_sorted

a = heap_sort(a)
a.reverse()

al = 0
bo = 0

flag = True
for i in a:
    if(flag):
        al += i
        flag = False
    else:
        bo += i
        flag = True
print(al - bo)

Submission status: Wrong Answer

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

def heap_sort(arr_ref):
    def swap(arr, a, b):
        tmp = arr[a]
        arr[a] = arr[b]
        arr[b] = tmp
    arr = arr_ref
    arr_sorted = []
    if(len(arr) == 2):
        if(len(arr) <= 2):
            if(arr[0] < arr[1]):
                swap(arr, 0, 1)
            arr_sorted = arr
    else:
        while(True):
            while(True):
                flag_swap = True
                for i in range(int(len(arr)/2)): #配列の一番最後の根まで
                    if((arr[i] < arr[i*2]) and (arr[i] < arr[i*2 + 1])):
                        if(arr[i*2] > arr[i*2 + 1]):
                            swap(arr, i, i*2)
                        else:
                            swap(arr, i, i*2 + 1)
                    elif(arr[i] < arr[i*2]):
                        swap(arr, i, i*2)
                    elif(arr[i] < arr[i*2 + 1]):
                        swap(arr, i, i*2 + 1)
                    else:
                        flag_swap = False
                if(not flag_swap):
                    break
            arr_sorted.append(arr[0])
            arr[0] = arr[-1]
            del arr[-1]
            if(len(arr) <= 2):
                if(arr[0] < arr[1]):
                    swap(arr, 0, 1)
                arr_sorted.extend(arr)
                break
    arr_sorted.reverse()
    return arr_sorted

a = heap_sort(a)
a.reverse()

al = 0
bo = 0

flag = True
for i in a:
    if(flag):
        al += i
        flag = False
    else:
        bo += i
        flag = True
print(al - bo)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def draw_max_card(card_list):
    max_card = max(card_list)
    card_list.remove(max_card)
    return max_card

n = int(input())
card_list = list(map(int, input().split(" ")))
points_alice = 0
points_bob  = 0
for count in range(1, n + 1):
    print(count)
    if count % 2 != 0:
        points_alice += draw_max_card(card_list)
    else:
        points_bob += draw_max_card(card_list)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

print(a[0::2].sum() - a[1::2].sum())

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(map(int,input().split()))
alice=0
bob=0

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

print(alice-bob)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:

def main():
    n = int(input())
    cards = list(map(int, input().split()))
    alice_point = 0
    bob_point = 0

    cards.sort()
    for i in range(0, n):
        if i%2 == 0:
            alice_point += cards[i]
        else:
            bob_point += cards[i]

    print(alice_point - bob_point)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

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

    cards.sort()
    for i in range(0, n, 2):
        point = cards[i-1] - cards[i]
    print(point)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
 
a_sum = 0
b_sum = 0
for i in range(N//2):
    tup = (A_list[2*i], A_list[2*i + 1]) if A_list[2*i] > A_list[2*i + 1] else (A_list[2*i + 1], A_list[2*i])
    a_sum += tup[0]
    b_sum += tup[1]

print(a_sum - b_sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
 
a_sum = 0
b_sum = 0
for i in range(N//2):
  a,b = (A_list[2*i], A_list[2*i + 1]) if A_list[2*i] > A_list[2*i + 1] else (A_list[2*i + 1], A_list[2*i])
  a_sum += a
  b_sum += b

print(a_sum - b_sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

card.sort()

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

print(asum-bsum)

Submission status: Wrong Answer

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

card.sort()

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

print(asum-bsum)

Submission status: Wrong Answer

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

card.sort()

ans = 0
for i in range(n//2):
            ans += card[2*i]-card[2*i+1]
if n%2==1:
            ans += card[-1]

print(ans)

Submission status: Wrong Answer

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

card.sort()

for i in range(n//2):
            ans = card[2*i]-card[2*i+1]
if n%2==1:
            ans += card[-1]

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A=0
B=0

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

print(A-B)

Submission status: Wrong Answer

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

A=0
B=0

for i in range(n):
 if i%2 ==1:
  A += a[i]
 else:
  B += a[i]

print(A-B)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()

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

print(ans)

Submission status: Wrong Answer

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

X.sort()

x = sum(X)
b = sum(X[0::2])
a = x - b

print(a-b)

Submission status: Wrong Answer

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

alist = list()
for i in range(N):
    alist.append(max(a))
    a.remove(max(a))

Alice = 0
Bob = 0

if N == 1:
  result = alist[0]

elif N % 2 == 0:
  n = int(N/2)
  
  for j in range(n):
  	Alice += alist[(j - 1 )*2 ]
  
  for k in range(n):
  	Bob += alist[(k - 1) *2 + 1]
    
  result = Alice - Bob

else:
  n = int((N + 1)/2)
  
  for j in range(n):
  	Alice += alist[(j - 1 )*2 ]
  
  for k in range(n):
  	Bob += alist[(k - 1) *2 + 1]
    
  result = Alice - Bob




print(result)

Submission status: Wrong Answer

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

alist = list()
for i in range(N):
    alist.append(max(a))
    a.remove(max(a))


if N % 2 == 0:
  n = int(N/2)
else:
  n = int((N + 1)/2)

Alice = 0
for j in range(n):
  Alice += alist[(j - 1 )*2 ]
  
Bob = 0
for k in range(n):
  Bob += alist[(k - 1) *2 + 1]
        
result = Alice - Bob
print(result)

Submission status: Wrong Answer

Solution code:
N=int(input())
numbers=list(map(int,input().split()))
new_numbers=sorted(numbers,reverse=True)
Alice=0

Bob=0
for i in range(N//2+N%2):
    Alice+=numbers[2*i]
for i in range(N//2):
    Bob+=numbers[2*i+1]
print(Alice-Bob)

Submission status: Wrong Answer

Solution code:
N=int(input())
numbers=list(map(int,input().split()))
for i in range(N):
    for k in range(i+1):
        if numbers[k]<numbers[i]:
            temp=numbers[k]
            numbers[k]=numbers[i]
            numbers[i]=temp
            break
Alice=0

Bob=0
for i in range(N//2+N%2):
    Alice+=numbers[2*i]
for i in range(N//2):
    Bob+=numbers[2*i+1]
print(Alice-Bob)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
numbers=list(map(int,input().split()))
for i in range(1,N):
    for k in range(i):
        if numbers[k]<numbers[i]:
            temp=numbers[k]
            numbers[k]=numbers[i]
            numbers[i]=temp
            break
Alice=0
Bob=0
for i in range(N//2+N%2):
    Alice+=numbers[2*i]
for i in range(N//2):
    Bob+=numbers[2*i+1]
print(Alice-Bob)

Submission status: Wrong Answer

Solution code:
N=int(input())
numbers=list(map(int,input().split()))
for i in range(1,N):
    for k in range(i):
        if numbers[k]<numbers[i]:
            temp=numbers[k]
            numbers[k]=numbers[i]
            numbers[i]=temp
            break
print(numbers)
Alice=0
Bob=0
for i in range(N//2+N%2):
    Alice+=numbers[2*i]
for i in range(N//2):
    Bob+=numbers[2*i+1]
print(Alice,Bob)
print(Alice-Bob)

Submission status: Wrong Answer

Solution code:
N=int(input())
A_list=list(map(int, input().split()))
A_list = sorted(A_list, reverse=True)
total = 0
for i in range((N+1)//2):
  total = total + A_list[i*2]
print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = max(a) -min(a)
print(ans)

Submission status: Wrong Answer

Solution code:
card_n = int(input())
card_collection = list(map(int, input().split()))

scores = {"alice" : 0, "bob" :0}
card_collection.sort()
for i, card in enumerate(card_collection):
    if i % 2 == 0:
        scores['bob'] += card
    else:
        scores['alice'] += card
print(scores['alice'] - scores['bob'])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

list=sorted(list)[::-1]
print(list)
A=0
B=0

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

Submission status: Wrong Answer

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

a.sort()

ALICE = sum(a[::2])
BOB = sum(a[1::2])

print(ALICE-BOB)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
na=sorted(a)
Alice=0
Bob=0

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

print(Alice-Bob)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if __name__ == "__main__":
  main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
alice = 0
bob = 0
cards = [int(val) for val in input().split()]

cards = sorted(cards, reverse=True)

print(cards)

for i in range(n):
    if i % 2 == 0:
        alice += int(cards[i])
    else:
        bob += int(cards[i])
        
print(alice - bob)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
Alice = list()
Bob = list()
print(a)
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: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
Alice = list()
Bob = list()
print(a)
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: Wrong Answer

Solution code:
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	n = II()
	a = LI()
	a.sort(reverse=True)
	a = np.array(a)
	print(np.sum(a[0::2]) - np.sum(a[1::]))


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
Alice = []
Bob = []
for i in range(1,N+1):
    if i % 2 != 0:
        Alice.append(A[i-1])
    else:
        Bob.append(A[i-1])
print(sum(Alice)-sum(Bob))

Submission status: Wrong Answer

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

a.sort(reverse=True)
print(a)
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: Wrong Answer

Solution code:

n = int(input())

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

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

Bob = sum(a)-Alice

print(Alice-Bob)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

for i in reversed(range(1, N)):
    for j in reversed(range(1, i+1)):
        if a[j-1] < a[j]:
            s = a[j-1]
            a[j-1] = a[j]
            a[j] = s

for i in range(0, N, 2):
    sum_a += a[i]
for i in range(1, N, 2):
    sum_b += a[i]

diff = sum_a - sum_b
print(diff)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8

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

for i in reversed(range(1, N)):
    for j in reversed(range(1, i+1)):
        if a[j-1] < a[j]:
            s = a[j-1]
            a[j-1] = a[j]
            a[j] = s

for i in range(0, N, 2):
    sum_a += a[i]
for i in range(1, N, 2):
    sum_b += a[i]

diff = sum_a - sum_b
print(diff)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8

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

for i in reversed(range(1, N)):
    for j in reversed(range(1, i+1)):
        if a[j-1] < a[j]:
            s = a[j-1]
            a[j-1] = a[j]
            a[j] = s

for i in range(0, N, 2):
    sum_a += a[i]
for i in range(1, N, 2):
    sum_b += a[i]

print(sum_a - sum_b)

Submission status: Wrong Answer

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

M = sorted(M)

alice = 0
bob = 0

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

Submission status: Wrong Answer

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

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

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: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=a[0::2]#偶数番目
print(sum(a)-sum(b)*2)

Submission status: Wrong Answer

Solution code:
N = int(input())
score = list(map(int, input().split()))
total = 0
 
score.sort(reverse=True)
for i in range(0, N, 2):
  if i == N-2 or i == N-1:
    total = total + score[i]
  else:
    total = total + (score[i]-score[i+1])
 
print(total)

Submission status: Wrong Answer

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: Wrong Answer

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

#Aliceの得点（偶数番目の総和）
alice = 0
for i in range(int(N/2)):
    alice = alice + cards[2 * i]

#Bobの得点（奇数番目の総和）
bob = 0
for j in range(int(N/2)):
    bob = bob + cards[2 * j + 1]
    
print(alice - bob)

Submission status: Wrong Answer

Solution code:
# Author: cr4zjh0bp
# Created: Thu Mar 12 19:45:31 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
for i in range(N):
    if alice >= bob:
        bob += a[i]
    else:
        alice += a[i]

print(abs(alice - bob))

Submission status: Wrong Answer

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

print(Alice - Bob)

Submission status: Wrong Answer

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(i)    
print(sum(A)-sum(B))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
print(max(a) - min(a))

Submission status: Wrong Answer

Solution code:
N = int(input()) #入力値
A = sorted(map(int, input().split()), reverse = True)
Bob=0
Alice=0
print(A)
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: Wrong Answer

Solution code:
N = int(input()) #入力値
M = str(input())
A = M.split()
print (A[1])
Bob=0
Alice=0
A.reverse() #入力した値ソート
print(A)
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: Wrong Answer

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

alice = 0
bob = 0

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

print(alice - bob)

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
s=[[int(j) for j in input().split()] for i in range(2)]
n=s[0][0]
a=s[1]
alice=0
bob=0
max=0
for i in range(len(a)-1):
    if a[i]<=a[i+1]:
        temp=a[i]
        a[i]=a[i+1]
        a[i+1]=temp
for i in range(len(a)):
    if i % 2==0:
        alice+=a[i]
    else:
        bob+=a[i]
print(alice-bob)

Submission status: Wrong Answer

Solution code:
s=[[int(j) for j in input().split()] for i in range(2)]
n=s[0][0]
a=s[1]
print(a[0])
alice=0
bob=0
max=0
for i in range(len(a)-1):
    if a[i]<=a[i+1]:
        temp=a[i]
        a[i]=a[i+1]
        a[i+1]=temp
for i in range(len(a)):
    if i % 2==0:
        alice+=a[i]
    else:
        bob+=a[i]
print(alice-bob)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

for i in range(N):
   for j in reversed(range(i+1,N)):
        print(i,j)
        if a[j] > a[j-1]:
            temp = a[j]
            a[j] = a[j-1]
            a[j-1] = temp

Alice = 0
Bob = 0

k = 0
count =1
while k < N:
    if count % 2 == 0:
        Bob += a[k]
    else:
        Alice += a[k]
    k += 1
    count += 1

print(Alice-Bob)

Submission status: Wrong Answer

Solution code:
n=int(input())
Aseq=input().split()
A=[]
for i in range(n):
    A.append(int(Aseq[i]))
A.sort()
AA=A[0::2]
AB=A[1::2]
print(sum(AA)-sum(AB))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = sorted(list(map(int, input().split())), reverse = True)
ans = 0
for i in range(n // 2):
    ans += l[i] - l[n - 1 - i]
if n & 1:
    ans += l[n // 2]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
input()
li = list(map(int, input().split()))
li.sort(reverse=True)
alice = [i for index,i in enumerate(li) if index % 2 == 0]
print(alice)

Submission status: Wrong Answer

Solution code:
# atcoder では WAになる。なんで。
N = int(input())
a = list(map(int,input().split()))
a = sorted(a,reverse =True)
#
alice = []
bob = []
alice_total = 0
bob_total = 0
ans = 0
#
if N%2 == 0:
    for i in range(int(N/2)):
        alice.append(a[2*i])
        bob.append(a[2*i + 1])
elif N!=1 and N%2==1:
    for j in range(int((N - 1)/2)):
        alice.append(a[2*j])
        alice.append(a[N - 1])
        bob.append(a[2*j + 1])
else:
    alice = a
#
alice_total = sum(alice)
bob_total = sum(bob)
ans = alice_total - bob_total
#
print(ans)

Submission status: Wrong Answer

Solution code:
# atcoder では WAになる。なんで。
N = int(input())
a = list(map(int,input().split()))
a = sorted(a,reverse =True)
#
alice = []
bob = []
alice_total = 0
bob_total = 0
ans = 0
#
if N%2 == 0:
    for i in range(int(N/2)):
        alice.append(a[2*i])
        bob.append(a[2*i + 1])
elif N!=1:
    for j in range(int((N - 1)/2)):
        alice.append(a[2*j])
        alice.append(a[N - 1])
        bob.append(a[2*j + 1])
else:
    alice = a
#
alice_total = sum(alice)
bob_total = sum(bob)
ans = alice_total - bob_total
#
print(ans)

Submission status: Wrong Answer

Solution code:
# atcoder では WAになる。なんで。
N = int(input())
a = list(map(int,input().split()))
a = sorted(a,reverse =True)
#
alice = []
bob = []
alice_total = 0
bob_total = 0
ans = 0
#
if N%2 == 0:
    for i in range(0,int(N/2)):
        alice.append(a[2*i])
        bob.append(a[2*i + 1])
else:
    for j in range(0,int((N - 1)/2)):
        alice.append(a[2*j])
        alice.append(a[N - 1])
        bob.append(a[2*j + 1])
#
alice_total = sum(alice)
bob_total = sum(bob)
ans = alice_total - bob_total
#
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
a = sorted(a,reverse =True)
#
alice = []
bob = []
alice_total = 0
bob_total = 0
ans = 0
#
if N%2 == 0:
    for i in range(0,int(N/2)):
        alice.append(a[2*i])
        bob.append(a[2*i+1])
else:
    for j in range(0,int((N -1)/2)):
        alice.append(a[2*j])
        alice.append(a[N-1])
        bob.append(a[2*j +1])

alice_total = sum(alice)
bob_total = sum(bob)
ans = alice_total - bob_total
#
print(ans)

Submission status: Wrong Answer

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

a.sort()

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

print(alice - bob)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(N//2):
  s+=A[2*i]-A[2*i+1]
if N%2==1:
  s+=A[N-1]
print(s)

Submission status: Wrong Answer

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

print(A-B)