Problem:


Score : 400 points

Problem Statement

There are N dishes of cuisine placed in front of Takahashi and Aoki.
For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N.

When Takahashi eats Dish i, he earns A_i points of happiness; when Aoki eats Dish i, she earns B_i points of happiness.

Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat.
Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end".

Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9

1 \leq B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
:
A_N B_N

Output

Print the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".

Sample Input 1

3
10 10
20 20
30 30

Sample Output 1

20

In this sample, both of them earns 10 points of happiness by eating Dish 1, 20 points by eating Dish 2, and 30 points by eating Dish 3.

In this case, since Takahashi and Aoki have the same "taste", each time they will choose the dish with which they can earn the greatest happiness. Thus, first Takahashi will choose Dish 3, then Aoki will choose Dish 2, and finally Takahashi will choose Dish 1, so the answer is (30 + 10) - 20 = 20.

Sample Input 2

3
20 10
20 20
20 30

Sample Output 2

20

In this sample, Takahashi earns 20 points of happiness by eating any one of the dishes 1, 2 and 3, but Aoki earns 10 points of happiness by eating Dish 1, 20 points by eating Dish 2, and 30 points by eating Dish 3.

In this case, since only Aoki has likes and dislikes, each time they will choose the dish with which Aoki can earn the greatest happiness. Thus, first Takahashi will choose Dish 3, then Aoki will choose Dish 2, and finally Takahashi will choose Dish 1, so the answer is (20 + 20) - 20 = 20.

Sample Input 3

6
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000

Sample Output 3

-2999999997

Note that the answer may not fit into a 32-bit integer.



Sample input:
3
10 10
20 20
30 30


Sample output:
20

Submission status: Wrong Answer

Solution code:
N = int(input())

X = []
for i in range(N):
    x, y = map(int, input().split())
    
    X.append([x+y,x,y])   


X.sort()

ansA = 0
ansB = 0

for index, i in enumerate(X):
    if index%2 == 0:
        ansA += i[1]
    else:
        ansB += i[2]

print(ansA - ansB)

Submission status: Wrong Answer

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python

N = int(input())
inp_list = [ list(map(int , input().split()))  for i in range(N)]

A = [ x[0] for x in inp_list]
B = [ x[1] for x in inp_list]

sum_list = [ A[i] + B[i] for i in range(N)] 

A_w_sum = sorted([ (sum_list[i], A[i]) for i in range(N)], reverse=True)
B_w_sum = sorted([ (sum_list[i], B[i]) for i in range(N)], reverse=True)


takahashi_sum = sum( [x[1] for x in A_w_sum[::2]] , 0)
aoki_sum = sum(      [x[1] for x in B_w_sum[1::2]], 0)

print(takahashi_sum - aoki_sum)

Submission status: Wrong Answer

Solution code:
n=int(input())
a_=[]
b_=[]

for i in range(n):
    a,b = map(int,input().split())
    a_.append([a+b,a,i])
    b_.append([a+b,b,i])

sa_ = sorted(
  a_,
  key = lambda x: (x[0], x[1]),
  reverse=True
)
sb_ = sorted(
  b_,
  key = lambda x: (x[0], x[1]),
  reverse=True
)

i_={}
res=0

for i in range(n):
    if i % 2 :
        item = sb_.pop()
        while ( item[2] in i_ ) :
            item = sb_.pop(0)
        res -= item[1]
        i_[item[2]]=1
    else :
        item = sa_.pop()
        while ( item[2] in i_ ) :
            item = sa_.pop(0)
        res += item[1]
        i_[item[2]]=1

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = []
bs = 0
for i in range(n):
  a,b = map(int,input().split())
  bs += b
  c.append(a+b)

c.sort()

ans = -bs
for i in range(n):
  if i%2==0: ans += c[i]
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

dish_list = []
for i in range(n):
    ai, bi = list(map(int, input().split()))
    dish_list.append([ai, bi, ai*bi*1])


dish_list.sort(key = lambda x:x[2], reverse=True)


a, b =0, 0
turn = 1
for i in range(n):
    if turn ==1:
        a+=dish_list[i][0]
    else:
        b+=dish_list[i][1]
    turn*=-1


print(a-b)

Submission status: Wrong Answer

Solution code:
n = int(input())

dish_list = []
for i in range(n):
    ai, bi = list(map(int, input().split()))
    dish_list.append([ai, bi, ai*bi])


dish_list.sort(key = lambda x:x[2], reverse=True)


a, b =0, 0
turn = 1
for i in range(n):
    if turn ==1:
        a+=dish_list[i][0]
    else:
        b+=dish_list[i][1]
    turn*=-1


print(a-b)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
T = [line.split() for line in sys.stdin.readlines()]
res = 0
for i, t in enumerate(sorted([(int(a) + int(b), int(b)) for a, b in T])):
	if i % 2 == 0:
		res += t[0]
	res -= t[1]

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_b = []
b_sum = 0
for i in range(n):
    ai, bi = map(int, input().split())
    a_b.append(ai+bi)
    b_sum += bi
a_b.sort()
ans = 0
for i in range(len(a_b)):
    if i%2==0:
        ans += a_b[i]
print(ans-b_sum)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    vals = []
    scores_a = []
    scores_b = []

    for i in range(n):
        a, b = [int(strn) for strn in input().split()]
        vals.append([a, b, True])
        scores_a.append((a * a * (b/a), i))
        scores_b.append((b * b * (a/b), i))

    scores_a.sort(key=lambda x: x[0])
    scores_b.sort(key=lambda x: x[0])

    total = 0
    count = 0
    while True:
        # Turn A
        candidate = scores_a[-1][1]
        candidate_live = vals[candidate][2]
        # print(candidate, candidate_live)
        while not candidate_live:
            # print("####1{}".format(scores_a))
            del scores_a[-1]
            # print("####2{}".format(scores_a))
            candidate = scores_a[-1][1]
            candidate_live = vals[candidate][2]

        total += vals[candidate][0]
        count += 1
        vals[candidate][2] = False
        del scores_a[-1]

        if count == len(vals):
            break

        # Turn B
        candidate = scores_b[-1][1]
        candidate_live = vals[candidate][2]
        while not candidate_live:
            # print("####3{}".format(scores_b))
            del scores_b[-1]
            # print("####4{}".format(scores_b))
            candidate = scores_b[-1][1]
            candidate_live = vals[candidate][2]

        total -= vals[candidate][1]
        count += 1
        vals[candidate][2] = False

        if count == len(vals):
            break

    print(total)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from statistics import mean, median,variance,stdev
import sys
import math
import fractions

def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

n = ip()                              #入力整数1つ
#n,k= (int(i) for i in input().split())      #入力整数横2つ
#x,y,z = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列

#jの変数はしようできないので注意
a = []
b = []
c = []


for i in range(n):
    x,y = (int(i) for i in input().split())
    b.append(y)
    a.append(x)
sum = 0
c = [a,b]
c[0].sort(reverse = True)

for i in range(n):
    if i%2==0:
        sum+=c[0][i]
    else: sum-= c[1][i]

print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for i in range(N):
  a, b = map(int, input().split())
  A.append([a, b, a-b])

sorted(A, key=lambda x:x[2])
turn = 0
total = 0

while A:
  tmp = A.pop()
  if turn == 0:
    total += tmp[0]
    turn = 1
  else:
    total -= tmp[1]
    turn = 0

print(total)

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter


def r(n, ab):

    ss = [x + [x[0] + x[1]] for x in ab]
    ss.sort(key=itemgetter(1), reverse=True)
    
    scr = 0
    sente = True
    for s in ss:
        if sente:
            scr += s[0]
        else:
            scr -= s[1]
        sente = not sente

    return scr

def main():
    input = sys.stdin.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    print(r(n, ab))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter


def r(n, ab):

    ss = [x + [int((x[0] + x[1])/2)] for x in ab]
    ss.sort(key=itemgetter(1), reverse=True)
    
    scr = 0
    sente = True
    for s in ss:
        if sente:
            scr += s[0]
        else:
            scr -= s[1]
        sente = not sente

    return scr

def main():
    input = sys.stdin.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    print(r(n, ab))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
 
def main():
    N = int(input())
    AB = [tuple(map(int, input().split())) for _ in [0] * N]
 
    dish = sorted(AB, key=lambda x: x[0] + x[1])
    taka, aoki = 0, 0
    for i in range(N):
        aoki += dish[i][1]
        if not i % 2:
            taka += sum(dish[i])
    print(taka - aoki)
 
input = lambda: stdin.readline()
main()

Submission status: Wrong Answer

Solution code:
import heapq
import sys
N = int(input())
a,b = [], []
for i in range(N):
    ai,bi = map(int, input().split())
    heapq.heappush(a, (ai+bi,ai,i))
    heapq.heappush(b, (ai+bi,bi,i))
# print(a, b)
aoki = []
taka = []
used = set([-1])
for i in reversed(range(N)):
    if i%2==1: # aoki
        m = 1e10
        k = -1
        while k in used and b:
            v,vv,k = heapq.heappop(b)
        used.add(k)
        aoki.append(vv)
    else:
        m = 1e10
        k = -1
        while k in used and a:
            v,vv,k = heapq.heappop(a)
        used.add(k)
        taka.append(vv)
    #print(taka, aoki, used)
print(abs(sum(taka)-sum(aoki)))

Submission status: Wrong Answer

Solution code:
n = int(input())
D = []
A = []
B = []
m = 1000000000
res = 0
for i in range(n):
    a,b = map(int,input().split())
    point = a+b
    D.append([point,i])
    A.append(a)
    B.append(b)
else:
    D.sort()
    D.reverse()

for i in range(n):
    if n%2 == 0:
        res += A[(D[i][1])]
    else:
        res -= B[(D[i][1])]
else:
    print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
D = []
A = []
B = []
m = 1000000000
res = 0
for i in range(n):
    a,b = map(int,input().split())
    point = a+b
    D.append([point,i])
    A.append(a)
    B.append(b)
else:
    D.sort()
    D.reverse()

for i in range(n//2):
    res += A[(D[i][1])]
    res -= B[(D[i+1][1])]
else:
    if n%2 ==1:
        res += A[D[n-1][1]]
    print(res)

Submission status: Wrong Answer

Solution code:
from sys import stdin

def main():
    N = int(input())
    AB = [tuple(map(int, input().split())) for _ in [0] * N]

    AB.sort(reverse=1)
    dish = sorted(AB, key=lambda x: x[0] + x[1])
    taka, aoki = 0, 0
    for i in range(N):
        if i % 2:
            aoki += dish[i][1]
        else:
            taka += dish[i][0]
    print(taka - aoki)

input = lambda: stdin.readline()
main()

Submission status: Wrong Answer

Solution code:
from sys import stdin

def main():
    N = int(input())
    AB = [tuple(map(int, input().split())) for _ in [0] * N]

    dish = sorted(AB, key=lambda x: x[0] + x[1])
    taka, aoki = 0, 0
    for i in range(N):
        if i % 2:
            aoki += dish[i][1]
        else:
            taka += dish[i][0]
    print(taka - aoki)

input = lambda: stdin.readline()
main()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
L=[]
for j in range(n):
  L.append([l[j][0]+l[j][1],j])
L.sort()
c=0
for k in range(n-1,-1,-1):
  if k%2==0:
    c+=l[L[k][1]][0]
  else:
    c-=l[L[k][1]][1]
print(c)

Submission status: Wrong Answer

Solution code:
N=input()

L=[]
for i in range(N):
	a,b=map(int,raw_input().split())
	L.append( (a+b,a,b) ) 


L.sort(key=lambda x: x[0])


ans=0
for i in range(N):
	if i%2==0:
		ans+=L[i][1]
	else:
		ans-=L[i][2]

print ans

Submission status: Wrong Answer

Solution code:
import warnings
warnings.filterwarnings('ignore')
import numpy as np
N = int(input())
arr = []
for i in range(N):
    arr.append([int(x) for x in input().split()])
score = int(-np.sum(arr, axis=0)[1])
arr = np.sum(arr, axis=1)
A_choices = [arr[i] for i in range(len(arr)) if (i+1) % 2 == 1]
score += int(sum(A_choices))
print(int(score))

Submission status: Wrong Answer

Solution code:
import heapq
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

AB = sorted([i for i in range(N)], key=lambda x: A[x] + B[x], reverse=True)
x, y = 0, 0
for (i, cnt) in enumerate(AB):
    if cnt % 2 == 0: 
        x += A[i]
    else:
        y += B[i]
print(x - y)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
arr = []
for i in range(N):
    arr.append([int(x) for x in input().split()])
score = int(-np.sum(arr, axis=0)[1])
arr = np.sum(arr, axis=1)
A_choices = [arr[i] for i in range(len(arr)) if (i+1) % 2 == 1]
score += int(sum(A_choices))
print(score)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = np.arange((n))
b = np.arange((n))

for i in range(n):
    a[i], b[i] = map(int, input().split())

#######

diff = np.arange((n))
for i in range(n):
    diff[i] = a[i] - b[i]

array = (np.argsort(diff))

a_score = 0
b_score = 0
for i in range(n):
    if (i % 2 == 0):
        a_score += a[array[i]]
    else:
        b_score += b[array[i]]

print(a_score - b_score)

Submission status: Wrong Answer

Solution code:
import time
n = int(input())
li_a = []
li_b = []
a_score = b_score = 0

counter = 0

for i in range(n):
    inputs = [int(i) for i in input().split()]
    li_a.append(inputs[0])
    li_b.append(inputs[1])

start = time.time()
while True:
    # Turn A
    max_a_index = li_a.index(max(li_a))
    max_b_index = li_b.index(max(li_b))
    if li_b[max_a_index] == max(li_b):
        a_score += li_a.pop(max_a_index)
        li_b.pop(max_a_index)
    elif li_a[max_b_index] == max(li_a):
        a_score += li_a.pop(max_b_index)
        li_b.pop(max_b_index)
    else:
        li_c = [li_a[j] - li_b[j] for j in range(len(li_a))]
        a_score += li_a.pop(li_c.index(min(li_c)))
        li_b.pop(li_c.index(min(li_c)))

    # 終了判定
    counter += 1
    if counter == n:
        break

    # Turn B
    max_a_index = li_a.index(max(li_a))
    max_b_index = li_b.index(max(li_b))
    if li_a[max_b_index] == max(li_a):
        b_score += li_b.pop(max_b_index)
        li_a.pop(max_b_index)
    elif li_b[max_a_index] == max(li_b):
        b_score += li_b.pop(max_a_index)
        li_a.pop(max_a_index)
    else:
        li_c = [li_a[j] - li_b[j] for j in range(len(li_a))]
        b_score += li_b.pop(li_c.index(max(li_c)))
        li_a.pop(li_c.index(max(li_c)))
    # 終了判定
    counter += 1
    if counter == n:
        break
print(a_score - b_score)

elapsed_time = time.time() - start
print ("while_time:{0}".format(elapsed_time) + "[sec]")

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = []
b = []

for _ in range(n):
    ta,tb = map(int, input().split())
    a.append(ta)
    b.append(tb)

a = np.array(a)
b = np.array(b)
idx_a = np.lexsort((a, b))[::-1]
takahashi_idx = [idx_a[i] for i in range(len(idx_a)) if i%2 == 0]
idx_b = np.lexsort((b, a))[::-1]
aoki_idx = [idx_b[i] for i in range(len(idx_b)) if i%2 == 1]

print(a[takahashi_idx].sum() - b[aoki_idx].sum())

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = []
b = []

for _ in range(n):
    ta,tb = map(int, input().split())
    a.append(ta)
    b.append(tb)

a = np.array(a)
b = np.array(b)
idx_a = np.lexsort((a, b))[::-1]
takahashi_idx = [idx_a[i] for i in range(len(idx_a)) if i%2 == 0]
idx_b = np.lexsort((b, a))[::-1]
aoki_idx = [idx_b[i] for i in range(len(idx_b)) if i%2 == 1]

takahashi = []
aoki = []
    
takahashi = a[takahashi_idx]
aoki = b[aoki_idx]

print(sum(takahashi) - sum(aoki))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
arr = []
for i in range(N):
    arr.append([int(x) for x in input().split()])
score = -np.sum(arr, axis=0)[1]
arr = np.sum(arr, axis=1)
A_choices = [arr[i] for i in range(len(arr)) if (i+1) % 2 == 1]
score += sum(A_choices)
print(score)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    ab = [[int(i) for i in input().split()] for _ in range(N)]
    arr = sorted([[a + b, a, b] for a, b in ab], key=lambda x: x[0])
    ans = 0
    for i in range(N):
        if i % 2 == 0:
            ans += arr[i][1]
        else:
            ans -= arr[i][2]
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
n = int(input())
happiness_hash = {}
for i in range(n):
    a, b = tuple(map(int, input().split(' ')))

    happiness_hash[i] = (a, b)

sorted_happiness = sorted(happiness_hash.items(), key = lambda x : x[1][0] + x[1][1], reverse = True)
print(sorted_happiness)

total = 0
i = 0
for k, v in sorted_happiness:
    happiness, selected = (0, k)
    if i % 2 == 0:
        happiness = v[0]
        total += happiness
    else:
        happiness = v[1]
        total -= happiness
    i += 1

print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
li = []
for i in range(n):
    a, b = map(int, input().split())
    li.append([a+b, a, b])

li = sorted(li)
for i in range(n):
    if i%2 == 0:
        ans += li[i][1]
    else:
        ans -= li[i][2]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
AB = [tuple(map(int,input().split())) for _ in range(n)]
all_b = sum([b for _,b in AB])
AB = sorted([a + b for a,b in AB],reverse=True)
print(AB)
ans = 0
for i in range(n):
    if i % 2 == 0:
        ans += AB[i]
print(ans - all_b)

Submission status: Wrong Answer

Solution code:
from sys import stderr, setrecursionlimit
setrecursionlimit(2147483647)
def getInt():
    return int(input())
def getInts():
    return [int(i) for i in input().split()]
def getIntLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInt())
    return res
def getIntsLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInts())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)
    
n = getInt()
dish = []
bsum = 0
for _ in range(n):
    a, b = getInts()
    bsum += b
    dish.append(a+b)
print(sum(dish[::2]) - bsum)

Submission status: Wrong Answer

Solution code:
N=int(input())
ps=[]
tp=[]
ap=[]
for i in range(N):
  p=input().split()
  ps.append([int(p[0])+int(p[1]),i])
  tp.append(int(p[0]))
  ap.append(int(p[1]))
    
def is_even(num):
  if num % 2 == 0:
    return True
  else:
    return False

T=0
A=0
calc=sorted(ps,reverse=True)
for i in range(N):
  p,j = calc.pop()
  if is_even(i):
    T+=tp[j]
  else:
    A+=ap[j]
print(T-A)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
m = [[0] * 3 for i in range(n)]
mm = [(0, 0, 0)] * n

for i in range(n):
    a, b = map(int, input().split())
    m[i][0] = a - b
    m[i][1] = a
    m[i][2] = b
    mm[i] = (a - b, a, b)

# 高橋くん:a - b が最大のものからとっていく。
#         a - b が同じものがある場合、bが大きいものをとっていく。
# 青木さん:a - b が最小のものからとっていく。
#         a - b が同じものがある場合、aが大きいものをとっていく。

if n == 1:
    print(m[0])
    exit()

m = sorted(m, key=lambda x:(x[0],-x[1],x[2]))

d = {}

for i in range(n):
    d.setdefault(m[i][0], []).append((m[i][1], m[i][2]))

takahashi = 0
aoki = 0

for i in range(n):
    if i % 2 == 0:
        k = max(d.keys())
        l = d[k]
        l = collections.deque(sorted(l, key=lambda x:(-x[1])))

        takahashi += d[k][0][0]

    else:
        k = min(d.keys())
        l = d[k]
        l = collections.deque(sorted(l, key=lambda x:(-x[0])))

        aoki += d[k][0][1]

    l.popleft()
    d[k] = l

    if not l:
        d.pop(k)

print(takahashi - aoki)

Submission status: Wrong Answer

Solution code:
base = int(input())

data = [[0 for i in range(3)] for j in range(base)]

for num in range(base):
    _num = input()
    _num = _num.split()
    data[num][0] = int(_num[0])+int(_num[1])
    data[num][1] = int(_num[0])
    data[num][2] = int(_num[1])

takahashi = 0
aoki = 0
data.sort()
data.reverse()

_num = 0
for num in range(base):
    if(_num == 0):
        takahashi += data[base-1-num][1]
        _num = 1

    elif(_num == 1):
        aoki += data[base-1-num][2]
        _num = 0

print(takahashi-aoki)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = []
x = 0
for i in range(n):
  a,b = map(int,input().split())
  x -= b
  ab.append(a+b)
ab.sort()
ab.reverse()
for i in range(round(n/2)):
  x += ab[i]
print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = []
x = 0
for i in range(n):
  a,b = map(int,input().split())
  x -= b
  ab.append(a+b)
ab.sort()
for i in range(round(n/2)):
  x += ab[i]
print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []

sc_a = 0
sc_b = 0

for i in range(N):
    x, y =  [int(x) for x in input().split()]
    A.append(x)
    B.append(y)



for j in range(N):
    if j % 2 == 0:
        if max(A) >= max(B):
            sc_a = sc_a + max(A)
            idx = A.index(max(A))
            del A[idx]
            del B[idx]
        else:
            idx = B.index(max(B))
            sc_a = sc_a + A[idx]
            del A[idx]
            del B[idx]
    else:
        if len(B) ==1:
            sc_b = sc_b + B[0]
        else:
            if max(B) >= max(A):
                idx = B.index(max(B))
                sc_b = sc_b + max(B)
                del B[idx]
                del A[idx]
            else:
                idx = A.index(max(A))
                sc_b = sc_b + B[idx]
                del B[idx]
                del A[idx]
        print(sc_b)
print(str(sc_a-sc_b))

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
abd = sorted([e[0]+e[1] for e in ab])

res = 0
for i in range(n):
    e = abd.pop(0)
    if i % 2 == 0:
        res += e

print(res-sum([e[1] for e in ab]))

Submission status: Wrong Answer

Solution code:
N = int(input())
A_dict = {}
B_dict = {}
i = 0
flg = 0
while i < N:
    l = list(map(int, input().split()))
    A = l[0]
    B = l[1]
    A_dict[str(i)] = A
    B_dict[str(i)] = B
    if flg == 0 and A != B:
        flg = 1
    i+=1

taka = 0
aoki = 0
for i in range(N):
    if flg == 0:
        A_max_key = max(A_dict, key=A_dict.get)
        taka += A_dict[str(A_max_key)]

        if len(A_dict) != 0:
            A_dict.pop(A_max_key)
        if len(B_dict) != 0:
            B_dict.pop(A_max_key)
        if len(B_dict) == 0:
            break

        B_max_key = max(B_dict, key=B_dict.get)
        aoki += max(B_dict.values())

        if len(A_dict) != 0:
            A_dict.pop(B_max_key)
        if len(B_dict) != 0:
            B_dict.pop(B_max_key)
        if len(A_dict) == 0:
            break
    else:
        B_max_key = max(B_dict, key=B_dict.get)
        taka += A_dict[B_max_key]

        if len(A_dict) != 0:
            A_dict.pop(B_max_key)
        if len(B_dict) != 0:
            B_dict.pop(B_max_key)
        if len(B_dict) == 0:
            break

        B_max_key = max(B_dict, key=B_dict.get)
        aoki += max(B_dict.values())

        if len(A_dict) != 0:
            A_dict.pop(B_max_key)
        if len(B_dict) != 0:
            B_dict.pop(B_max_key)
        if len(B_dict) == 0:
            break

print(taka, aoki)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A, B = [], []
Z = []

for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

    Z.append(a + b)

indexes = np.argsort(Z)
ans = 0
for i, cnt in enumerate(indexes):
    if cnt % 2 == 0:
        ans += A[i]
    else:
        ans -= B[i]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    AB = iml(N)
    ll = []
    for a, b in AB:
        ll.append(a + b)
    ind = np.argsort(ll)
    t = [AB[i][0] for i in ind[::2]]
    a = [AB[i][1] for i in ind[1::2]]
    return sum(t) - sum(a)


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
n = int(input())
happiness_hash = {}
for i in range(n):
    a, b = tuple(map(int, input().split(' ')))

    happiness_hash[i] = (a, b)

sorted_happiness = sorted(happiness_hash.items(), key = lambda x : x[1][0] + x[1][1], reverse = True)

total = 0
i = 0
for k, v in sorted_happiness:
    happiness, selected = (0, k)
    if i % 2 == 0:
        happiness = v[0]
        total += happiness
    else:
        happiness = v[1]
        total -= happiness
    print(selected, happiness)
    i += 1

print(total)

Submission status: Wrong Answer

Solution code:
# 2019/01/27
# NIKKEI Programming Contest 2019 - C
from operator import itemgetter

# Input
n = int(input())
ablist = list()

for idx in range(n):
    a, b = map(int, input().split())
    ablist.append([a, b, a-b])

ablist.sort(key=itemgetter(2), reverse=True)

tsum = 0
asum = 0

# Sum
for idx in range(n):
    if idx % 2 == 0:
        # Turn of Takahashi
        tsum += ablist[idx][0]
    else:
        # Turn of Aoki
        asum += ablist[idx][1]

ans1 = tsum - asum

# Output
print(ans1)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = []
X = 0
for i in range(N):
    a, b = map(int, input().split())
    L += [a+b]
    X += b
L.sort(reverse=True)
j = N-N//2
print(sum(L[0:j])-X)

Submission status: Wrong Answer

Solution code:
N = int(input())
dish = []
for i in range(N):
    a, b = map(int, input().split())
    dish.append((a+b, (a,b)))

# while True:
#     try:
#         a, b = map(int, input().split())
#     except EOFError:
#         break
#     dish.append((a+b, (a,b)))


l = sorted(dish)

t=a = 0
for i, (_, (a_i, b_i)) in enumerate(l):
    if i % 2 == 0:
        #takahashi
        t += a_i
    else:
        a += b_i

print(t-a)

Submission status: Wrong Answer

Solution code:
n = int(input())
a, b = [], []
for _ in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

ans = 0
for t in sorted(range(n), key=lambda i: (a[i] + b[i], b[i], a[i]), reverse=True):
    if t % 2 == 0:
        ans += a[t]
    else:
        ans -= b[t]
print(ans)

Submission status: Wrong Answer

Solution code:
N = input()

data = []

for i in range(N):
    A,B = map(int,raw_input().split())
    C = A+B
    data.append([C,A,B])

data.sort()

ans = 0

for i in range(N):
    if i%2 == 0:
        ans += data[i][1]
    else:
        ans -= data[i][2]

print ans

Submission status: Wrong Answer

Solution code:
n=int(input())
f=[0]*n
d=[list(map(int,input().split()))+[i]for i in range(n)]
t=sorted(d,key=lambda x:sum(x))
sumt=suma=0
while t:
    x=t.pop()
    while t and f[x[2]]:
        x=t.pop()
    if not f[x[2]]:
        sumt+=x[0]
    f[x[2]]=1
    if t:
        y=t.pop()
        while t and f[y[2]]:
            y=t.pop()
        if not f[y[2]]:
            suma+=y[1]
        f[y[2]]=1
print(sumt-suma)

Submission status: Wrong Answer

Solution code:
N = int(input())
dish = []
# for i in range(N):
#     a, b = map(int, input().split())
#     dish.append((a+b, (a,b)))

while True:
    try:
        a, b = map(int, input().split())
    except EOFError:
        break
    dish.append((a+b, (a,b)))


l = sorted(dish)

t=a = 0
for i, (_, (a_i, b_i)) in enumerate(l):
    if i % 2 == 0:
        #takahashi
        t += a_i
    else:
        a += b_i

print(t-a)

Submission status: Wrong Answer

Solution code:
n = int(input())
a, b = [], []
for _ in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

ans = 0
for t in sorted(range(n), key=lambda i: a[i] + b[i], reverse=True):
    if t % 2 == 0:
        ans += a[t]
    else:
        ans -= b[t]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [[int(i) for i in input().split()] for j in range(N)]
taka = []
aoki = []
for i in range(N):
    taka.append(L[i][0])
    aoki.append(L[i][1])

taka.sort()
aoki.sort()
A = []
B = []
if N % 2 == 0:
    for i in range(N//2):
         A.append(taka[2*i])
         B.append(aoki[2*i + 1])
else:
    for i in range((N-1)//2):
        A.append(taka[2*i])
        B.append(aoki[2*i+1])
        A.append(taka[-1])
print(sum(A)-sum(B))

Submission status: Wrong Answer

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