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:
def main():
    n = int(input())
    df = []
    for _ in range(n):
        a, b = map(int, input().split(' '))
        df.append([a-b, a, b])
    df.sort(reverse = True)
    result = 0
    for i in range(n):
        if i%2 == 0:
            x = df.pop(0)
            result += x[1]
        else:
            x = df.pop(0)
            result -= x[2]
    print(result)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

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

ans = 0
for i in range(n):
    ans += (-1)**i * food[i][i%2+1]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = []
for _ in range(n):
  a,b = map(int,input().split())
  ab.append([a,b])
ab.sort(key = lambda x:x[0]+x[1] ,reverse = True)
ans = sum([x[0]+x[1] for x in ab[0:(n+1)//2]])-sum([x[1] for x in ab])
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
AB=[list(map(int,input().split())) for _ in range(N)]
print(sum([-b for a, b in AB])+sum([a+b for a,b in AB][::2]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,*t=map(int,open(0).read().split())
t=sorted(zip(t[::2],t[1::2]),key=lambda v:v[0]+v[1])
print(sum(a for a,_ in t[::-2])-sum(b for _,b in t[-1::-2]))

Submission status: Wrong Answer

Solution code:
n,*t=map(int,open(0).read().split());t=sorted(zip(t[::2],t[1::2]),key=lambda v:v[0]+v[1]);print(sum(a for a,_ in t[::2])-sum(b for _,b in t[1::2]))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
ABs = []
for _ in range(N):
    A,B = inpl()
    ABs.append([A+B,A,B])

ABs.sort()
t = a = 0

for i,[AB,A,B] in enumerate(ABs):
    if i%2 == 0:
        t += A
    else:
        a += B

print(t-a)

Submission status: Wrong Answer

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

N = int(input())

lst_A = []
l_A_append = lst_A.append
lst_B = []
l_B_append = lst_B.append
for i in range(N):
    A, B = map(int, input().split())
    l_A_append([A + B, A, B, i])
    l_B_append([A + B, B, A, i])
    
lst_A.sort()
lst_B.sort()
# print (lst)
ans = 0
check_lst = [False] * N

index_A = 0
index_B = 0
count = 0
while count < N:
    if count % 2 == 0: #高橋くんの番
        while check_lst[lst_A[index_A][3]]: #使われているとき-->index_Aを増やす
            index_A += 1
        ans += lst_A[index_A][1]
        check_lst[lst_A[index_A][3]] = True
        index_A += 1
    else: #青木さんの番
        while check_lst[lst_B[index_B][3]]: #使われていないとき -->index_Bを増やす
            index_B += 1
        ans -= lst_B[index_B][1]
        check_lst[lst_B[index_B][3]] = True
        index_B += 1
    count += 1
print (ans)

Submission status: Wrong Answer

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

N = int(input())

lst = []
l_append = lst.append
for i in range(N):
    A, B = map(int, input().split())
    l_append([A + B, A, B, i])

lst.sort()
# print (lst)
ans = 0

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


# for i in range((N + 1)//2):
#     ans += lst[i][1]
# print (ans)
# for i in range((N + 1)//2, N):
#     ans -= lst[i][2]
print (ans)

Submission status: Wrong Answer

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

N = int(input())

lst = []
l_append = lst.append
for i in range(N):
    A, B = map(int, input().split())
    l_append([A - B, A, B, i])

lst.sort(reverse = True)

ans = 0
for i in range((N + 1)//2):
    ans += lst[i][1]
for i in range((N + 1)//2, N):
    ans -= lst[i][2]
print (ans)

Submission status: Wrong Answer

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

N = int(input())

lst = []
l_append = lst.append
for i in range(N):
    A, B = map(int, input().split())
    l_append([A - B, A, B, i])

lst.sort(reverse = True)

ans = 0
for i in range(N):
    if i % 2 == 0: #高橋くんの手番
        ans += lst[i][1]
    else:
        ans -= lst[i][2]
print (ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
b=[(i,sum(j)) for i,j in enumerate(a)]
b.sort(key=lambda x:x[1],reverse=True)
ans=0
for i in range(n):
	ans+=a[i][i%2]*(-1)**(i%2)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())

a = np.array(A)
b = np.array(B)
c = np.zeros(N)

# cはaとbの要素をすべて足したもの
c = a + b
# 降順にソート
csorted = np.sort(c)
# bの総和
bsum = np.sum(b)
# csortedの奇数番目を足していって最後にbsumの値を引けば求まる。
csum = 0
for i in range(N):
    if i % 2 == 0:
        csum += int(csorted[i])

ans = csum - bsum

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect


def main():
    n = int(input())
    a = []
    b = []
    dif = []
    for i in range(n):
        atmp,btmp = map(int,input().split())
        a.append([atmp,i])
        b.append([btmp,i])
#        dif.append([atmp-btmp,i])
#    adif = sorted(dif, key=lambda x: a[x[1]])
#    adif = list(reversed(adif))
#    adif = sorted(adif, key=lambda x: x[0])
#    bdif = sorted(dif, key=lambda x: b[x[1]], reverse=True)
#    bdif = sorted(bdif, key=lambda x: x[0])
    #bdif = list(reversed(bdif))
    atmp = sorted(a,key=lambda x: b[x[1]][0])
    afin = sorted(atmp, key=lambda x: x[0])
    btmp = sorted(b,key=lambda x: a[x[1]][0])
    bfin = sorted(btmp, key=lambda x: x[0])

    rem = [1 for i in range(n)]

    takahashi = 0
    aoki = 0
    tp = 0
    ap = 0
    for i in range(ceil(n/2)):
        while tp < n:
            if rem[afin[tp][1]]:
                takahashi += afin[tp][0]
                rem[afin[tp][1]]=0
#                print('tp is ' + str(adif[tp][1]))
                tp +=1
                break
            else:
                tp +=1
        while ap < n:
            if rem[bfin[ap][1]]:
                aoki += bfin[ap][0]
                rem[bfin[ap][1]]=0
#                print('ap is ' + str(bdif[ap][1]))

                ap+=1
                break
            else:
                ap += 1

    print(takahashi-aoki)




main()

Submission status: Wrong Answer

Solution code:
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect


def main():
    n = int(input())
    a = []
    b = []
    dif = []
    for i in range(n):
        atmp,btmp = map(int,input().split())
        a.append(atmp)
        b.append(btmp)
        dif.append([atmp-btmp,i])
    adif = sorted(dif, key=lambda x: a[x[1]])
    adif = list(reversed(adif))
    adif = sorted(adif, key=lambda x: x[0])
    bdif = sorted(dif, key=lambda x: b[x[1]], reverse=True)
    bdif = sorted(bdif, key=lambda x: x[0])
    #bdif = list(reversed(bdif))


    rem = [1 for i in range(n)]

    takahashi = 0
    aoki = 0
    tp = 0
    ap = 0
    for i in range(ceil(n/2)):
        while tp < n:
            if rem[adif[tp][1]]:
                takahashi += a[adif[tp][1]]
                rem[adif[tp][1]]=0
#                print('tp is ' + str(adif[tp][1]))
                tp +=1
                break
            else:
                tp +=1
        while ap < n:
            if rem[bdif[ap][1]]:
                aoki+= b[bdif[ap][1]]
                rem[bdif[ap][1]]=0
#                print('ap is ' + str(bdif[ap][1]))

                ap+=1
                break
            else:
                ap += 1

    print(takahashi-aoki)




main()

Submission status: Wrong Answer

Solution code:
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

#n,m = ips()
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(m)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
a = []
for i in range(n):
    a.append(iprow())
a.sort(reverse=True)
s = 0
ct = 0
for i in range(n):
    a[i][1]*=-1
for i in a:
    s+=i[ct]
    ct+=1
    ct%=2
print(s)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,reverse=True,key=lambda x:x[1]-x[0])
ans=0
for i in range(n):
  if i%2==0:
    ans+=arr[i][0]
  else:
    ans-=arr[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,reverse=True,key=lambda x:x[0])
arr=sorted(arr,reverse=True,key=lambda x:x[1]-x[0])
ans=0
for i in range(n):
  if i%2==0:
    ans+=arr[i][0]
  else:
    ans-=arr[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
dish =[list(map(int, input().split()))+[i] for i in range(N)]
def f1(l):
    a, b, i = l
    return b-a
def f2(l):
    a, b, i = l
    return a
def f3(l):
    a, b, i = l
    return b
d =[1]*N
dish.sort(key = f1)
d1 = sorted(dish, key = f2)
d2 = sorted(dish, key = f3, reverse = True)
d2 = collections.deque(d2)
cnt = 0
taka = 0
ao = 0
while cnt != N:
    if cnt % 2 == 0:
        while True:
            a, b, i = d1.pop()
            if d[i]:
                break
        taka += a
        cnt += 1
        d[i] = 0
    else:
        while True:
            a, b, i = d2.popleft()
            if d[i]:
                break
        ao += b
        cnt += 1
        d[i] = 0
print(taka - ao)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
for i in range(n):
    x,y = map(int,input().split())
    if i%2:
       ans-=(x+y)
    else:
        ans+=(x+y)
    ans+=(x-y)
print(ans//2)

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=0
for k,(s,t) in enumerate(sorted([list(map(int,input().split()))for i in range(n)],key=lambda x:x[1])):
    if k%2==0:
        ans+=s
    else:
        ans-=t
print(ans)

Submission status: Wrong Answer

Solution code:
import functools
def cmp(a, b):
    return A[a] + B[a] < A[b] + B[b]
if __name__=="__main__":
    n = int(input())
    A = [0 for i in range(n)]
    B = [0 for i in range(n)]
    C = [0 for i in range(n)]
    ans = 0
    for i in range(n):
        A[i], B[i] = [int(c) for c in input().split(' ')]
        C[i] = i
        ans -= B[i]
    sorted(C, key = functools.cmp_to_key(cmp))
    for i in range(n):
        if (i & 1) == 0:
            ans += A[C[i]] + B[C[i]]
    print(ans)

Submission status: Wrong Answer

Solution code:
import functools
def cmp(a, b):
    return A[a] + B[a] > A[b] + B[b]
if __name__=="__main__":
    n = int(input())
    A = [0 for i in range(n)]
    B = [0 for i in range(n)]
    C = [0 for i in range(n)]
    ans = 0
    for i in range(n):
        A[i], B[i] = [int(c) for c in input().split(' ')]
        C[i] = i
        ans -= B[i]
    sorted(C, key = functools.cmp_to_key(cmp))
    for i in range(n):
        if (i & 1) == 0:
            ans += A[C[i]] + B[C[i]]
    print(ans)

Submission status: Wrong Answer

Solution code:
import functools
def cmp(a, b):
    return A[a] + B[a] < A[b] + B[b]
if __name__=="__main__":
    n = int(input())
    A = [0 for i in range(n)]
    B = [0 for i in range(n)]
    C = [0 for i in range(n)]
    for i in range(n):
        A[i], B[i] = [int(c) for c in input().split(' ')]
        C[i] = i
    sorted(C, key = functools.cmp_to_key(cmp))
    ans = 0
    for i in range(n):
        if (i & 1) :
            ans -= B[C[i]]
        else:
            ans += A[C[i]]
    print(ans)

Submission status: Wrong Answer

Solution code:
import functools
def cmp(a, b):
    return A[a] + B[a] > A[b] + B[b]
if __name__=="__main__":
    n = int(input())
    A = [0 for i in range(n)]
    B = [0 for i in range(n)]
    C = [0 for i in range(n)]
    for i in range(n):
        A[i], B[i] = [int(c) for c in input().split(' ')]
        C[i] = i
    sorted(C, key = functools.cmp_to_key(cmp))
    ans = int(0)
    for i in range(n):
        if (i & 1) :
            ans -= B[C[i]]
        else:
            ans += A[C[i]]
    print(ans)

Submission status: Wrong Answer

Solution code:
import functools
def cmp(a, b):
    return A[a] + B[a] > A[b] + B[b]
if __name__=="__main__":
    n = int(input())
    A = [0 for i in range(n)]
    B = [0 for i in range(n)]
    C = [0 for i in range(n)]
    for i in range(n):
        A[i], B[i] = [int(c) for c in input().split(' ')]
        C[i] = i
    sorted(C, key = functools.cmp_to_key(cmp))
    ans = 0
    for i in range(n):
        if (i & 1) :
            ans -= B[i]
        else:
            ans += A[i]
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n==1:
  a, b =map(int, input().split())
  print(a)
else:
  ab = [[0] * n for i in range(3)]
  for i in range(n):
    ab[0][i], ab[1][i] = map(int, input().split())
    ab[2][i] = ab[0][i] + ab[1][i]
  sorted(ab, key=lambda x: x[2])
  print(sum(ab[0][0::2])-sum(ab[1][1::2]))

Submission status: Wrong Answer

Solution code:
# from operator import itemgetter

n = input()
dishes = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dishes.append((tmp[0] - tmp[1], tmp[1] - tmp[0], tmp[0], tmp[1]))

# dishes = [sorted(dishes, key=itemgetter(0, 2), reverse=True), sorted(dishes, key=itemgetter(1, 3), reverse=True)]
dishes = [sorted(dishes, key=lambda x: (x[0], x[2]), reverse=True), sorted(dishes, key=lambda x: (x[1], x[3]), reverse=True)]

# print(dishes[0])
# print(dishes[1])

point = [0, 0]
player = 0
while len(dishes[0]) > 0:
    dish = dishes[player].pop(0)
    # if player == 0:
    #     dish = dishes.pop(0)
    # else:
    #     dish = dishes.pop(len(dishes) - 1)

    dishes[int(not player)].remove(dish)
    # print(dish)
    point[player] += dish[player + 2]
    player = int(not player)
    # print(point)
print(point[0] - point[1])

Submission status: Wrong Answer

Solution code:
n = input()
dishes = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dishes.append((tmp[0] - tmp[1], tmp[0], tmp[1]))

sorted(dishes, key=lambda v: v[0], reverse=True)

point = [0, 0]
player = 0
while len(dishes) > 0:
    if player == 0:
        dish = dishes.pop(0)
    else:
        dish = dishes.pop(len(dishes) - 1)

    point[player] += dish[player + 1]
    player = int(not player)
print(point[0] - point[1])

Submission status: Wrong Answer

Solution code:
N = int(input())
L = []
K = []
S = 0
for i in range(N):
  L.append(list(map(int,input().split())))
for i in range(N):
  S += -L[i][1]
for i in range(N):
  K.append(L[i][0]+L[i][1])
K.sort()
K.reverse()
if N%2 == 0:
  for i in range(N//2):
    S += K[i]
else:
  for i in range(N//2+1):
    S += K[i]
print(S)

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())
A, B, C = np.zeros((3, N))
for num in range(N):
    A[num], B[num] = map(int, input().split())

SUM = 0
for num in range(N) :
    if num % 2 == 0 :
        max_index = A.argmax() + B[np.where(A == A.max())].argmax()
        SUM += A[max_index]
        A = np.delete(A, max_index)
        B = np.delete(B, max_index)
    else :
        max_index = B.argmax() + A[np.where(B == B.max())].argmax()
        SUM -= B[max_index]
        A = np.delete(A, max_index)
        B = np.delete(B, max_index)

print(SUM)

Submission status: Wrong Answer

Solution code:
#C問題
N=int(input())
A=[]
B=[]
C=[]
for i in range(0,N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(a+b)
C.sort()
C.reverse()
point=-sum(B)
print(point)
i=0
while i<N:
    point=point+C[i]
    i=i+2
print(point)

Submission status: Wrong Answer

Solution code:
#C問題
N=int(input())
A=[]
B=[]
C=[]
for i in range(0,N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(a+b)
C.sort()
C.reverse()
point=-sum(B)
for i in range(N//2+N%2):
    point=point+C[i]
print(point)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
B=[]
for i in range(0,N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
for i in range(0,N):
    C=[[A[i],A[i]-B[i]] for i in range(N)]
    D=[[B[i],B[i]-A[i]] for i in range(N)]
#print(C)
#無名関数はいいぞ
C.sort(key=lambda x: x[1])
D.sort(key=lambda x: x[1])
#print(C)
#print(D)
point=0
for i in range(N//2+N%2):
    point=point+C[i][0]
for i in range(N//2):
    point=point-D[i][0]
print(point)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
B=[]
for i in range(0,N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
for i in range(0,N):
    C=[[A[i],B[i]-A[i]] for i in range(N)]
    D=[[B[i],A[i]-B[i]] for i in range(N)]
#print(C)
#無名関数はいいぞ
C.sort(key=lambda x: x[1])
D.sort(key=lambda x: x[1])
point=0
for i in range(N//2+N%2):
    point=point+C[i][0]
for i in range(N//2):
    point=point-D[i][0]
print(point)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [[] for _ in range(N)]
eat = [True for i in range(N)]
for i in range(N):
    a,b = map(int,input().split())
    s[i] = (a,b,i)
st = sorted(s,key=lambda x:x[0],reverse=True)
sa = sorted(s,key=lambda x:x[1],reverse=True)
i = 0
tk,ao = 0,0
ti,ai = 0,0
while i<N:
    if i%2==0:
        while not eat[st[ti][2]]:
            ti += 1
        tk += st[ti][0]
        eat[st[ti][2]] = False
    else:
        while not eat[sa[ai][2]]:
            ai += 1
        ao += sa[ai][1]
        eat[sa[ai][2]] = False
    i += 1
print(tk-ao)

Submission status: Wrong Answer

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

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N = input()
ls = []
for _ in range(N):
    A, B = map(int, raw_input().split())
    ls.append((A + B, A, B))
ls.sort()

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

print ans

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort(key=sum, reverse=True)

sol = 0
import sys
print(sys.maxsize)

for i, x in enumerate(ab):
  if i % 2:
    sol -= ab[i][1]
  else:
    sol += ab[i][0]

print(sol)

Submission status: Wrong Answer

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

o = list(range(n))
o.sort(key=lambda x: d[x], reverse=True)

sol = 0
for i in o:
  if i % 2:
    sol -= ab[i][1]
  else:
    sol += ab[i][0]

print(sol)

Submission status: Wrong Answer

Solution code:
def get_ans(pairs):
    pairs = sorted(pairs, reverse=True)
    score = 0
    flg = 0
    for a,b in pairs:
        score += a*(1-flg) - b*flg
        flg = 1- flg
    return score

if __name__ == '__main__':
    n = int(input())
    p = []
    for i in range(n):
        p.append(tuple(map(int, input().split())))

    print(get_ans(p))

Submission status: Wrong Answer

Solution code:
def get_ans(pairs):
    pairs = sorted(pairs)
    score = 0
    flg = 0
    for a,b in pairs:
        score += a*(1-flg) - b*flg
        flg = 1- flg
    return score

if __name__ == '__main__':
    n = int(input())
    p = []
    for i in range(n):
        p.append(tuple(map(int, input().split())))

    print(get_ans(p))

Submission status: Wrong Answer

Solution code:
N=int(input())
AB=[[0,0]for i in range(N)]
for i in range(N):
    AB[i][0],AB[i][1]=map(int,input().split())
t_delta_AB=[[0,0,i] for i in range(N)]
for i in range(N):
    t_delta_AB[i][1]=AB[i][1]-AB[i][0]
    t_delta_AB[i][0]=AB[i][0]
t_delta_AB.sort(key= lambda x:(x[0],x[1]),reverse=True)
print(t_delta_AB)
a_delta_AB=[[0,0,i] for i in range(N)]
for i in range(N):
    a_delta_AB[i][1]=AB[i][0]-AB[i][1]
    a_delta_AB[i][0]=AB[i][1]
a_delta_AB.sort(key= lambda x:(x[0],x[1]),reverse=True)
takahashi_score=0
aoki_score=0
buf=[]
t=0
a=0
for i in range(N):
    if i%2==0:
        n=t
        while 1:
            if not(t_delta_AB[n][2] in buf):
                takahashi_score+=t_delta_AB[n][0]
                buf.append(t_delta_AB[n][2])
                t=n
                break
            n+=1
    else:
        n=a
        while 1:
            if not(a_delta_AB[n][2] in buf):
                aoki_score+=a_delta_AB[n][0]
                buf.append(a_delta_AB[n][2])
                a=n
                break
            n+=1

print(takahashi_score,aoki_score)
print(takahashi_score-aoki_score)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = []
for i in range(N):
    l.append(list(map(int, input().split())))
    l[i] += [i]
lA = sorted(l, key=lambda x: (x[0], -x[1]))
lB = sorted(l, key=lambda x: (-x[1]))
A = B = 0
while lA or lB:
    #A
    if i % 2 == 0:
        tmp = lA.pop(0)
        A += tmp[0]
        lB.remove(tmp)
    #B
    else:
        tmp = lB.pop(0)
        B += tmp[1]
        lA.remove(tmp)
    i += 1
print(A-B)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
ab = [0 for i in range(n)]
for i in range(n):
    ab[i] = list(map(int,input().split()))
abt = np.array(ab).T
kfd = 0
for i in range(n-1):
    if i%2 == 0:
        a = abt[0]
        afind = np.argmax(a)
        asind = np.argmax(np.concatenate((a[:afind],a[afind+1:])))
        b = abt[1]
        bfind = np.argmax(b)
        bsind = np.argmax(np.concatenate((b[:bfind],b[bfind+1:])))
        if a[afind]-a[asind] >= b[bfind]-b[bsind]:
            kfd = kfd + a[afind]
            abt = np.delete(abt,afind,1)
        else:
            kfd = kfd + abt[0][bfind]
            abt = np.delete(abt,bfind,1)
    else:
        afind = np.argmax(abt[0])
        asind = np.argmax(np.concatenate((abt[0][:afind],abt[0][afind+1:])))
        bfind = np.argmax(abt[1])
        bsind = np.argmax(np.concatenate((abt[1][:bfind],abt[1][bfind+1:])))
        if abt[0][afind]-abt[0][asind] >= abt[1][bfind]-abt[1][bsind]:
            kfd = kfd - abt[0][afind]
            abt = np.delete(abt,afind,1)
        else:
            kfd = kfd - abt[1][bfind]
            abt = np.delete(abt,bfind,1)
kfd = kfd + abt[0][0]
print(kfd)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    A, B = [], []
    for n in range(N):
        a, b = map(int, input().split())
        A.append([a, n])
        B.append([b, n])

    A.sort(reverse=True)
    B.sort(reverse=True)

    tak_p, ao_p = 0, 0
    tak_i, ao_i = 0, 0
    closed = [False for _ in range(N)]
    done = False
    while not done:
        while tak_i != N:
            if not closed[A[tak_i][1]]:
                tak_p += A[tak_i][0]
                closed[A[tak_i][1]] = True
                tak_i += 1
                break
            tak_i += 1
        else:
            done = True

        if done:
            break

        while ao_i != N:
            if not closed[B[ao_i][1]]:
                ao_p += B[ao_i][0]
                closed[B[ao_i][1]] = True
                ao_i += 1
                break
            ao_i += 1
        else:
            done = True

    print(tak_p - ao_p)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    score = []
    for n in range(N):
        a, b = map(int, input().split())
        score.append([a-b, -a, b])

    score.sort()

    tak_p, ao_p = 0, 0
    n = 0
    while n != N:
        tak_p -= score[n][1]
        n += 1

        if n == N:
            break
        ao_p += score[N-n-1][2]
        n += 1

    print(tak_p - ao_p)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    # A, B = [], []
    score = []
    for n in range(N):
        a, b = map(int, input().split())
        # A.append([n, a])
        # B.append([n, b])
        score.append([a-b, a, b])

    score.sort()
    closed = [False for _ in range(N)]

    tak_p, ao_p = 0, 0
    n = 0
    while n != N:
        tak_p += score[n][1]
        n += 1

        if n == N:
            break
        ao_p += score[N-n-1][2]
        n += 1

    print(tak_p - ao_p)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    # A, B = [], []
    score = []
    for n in range(N):
        a, b = map(int, input().split())
        # A.append([n, a])
        # B.append([n, b])
        score.append([n, a-b, a, b])

    score.sort(key=lambda x: x[1])
    closed = [False for _ in range(N)]

    tak_p, ao_p = 0, 0
    n = 0
    while n != N:
        tak_p += score[n][2]
        n += 1

        if n == N:
            break
        ao_p += score[N-n-1][3]
        n += 1

    print(tak_p - ao_p)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    # A, B = [], []
    score = []
    for n in range(N):
        a, b = map(int, input().split())
        # A.append([n, a])
        # B.append([n, b])
        score.append([n, a-b, a, b])

    score.sort(key=lambda x: x[1])
    closed = [False for _ in range(N)]

    tak_p, ao_p = 0, 0
    n = 0
    while n != N:
        tak_p += score[n][2]
        n += 1

        if n == N:
            break
        ao_p += score[n][3]
        n += 1

    print(tak_p - ao_p)

Submission status: Wrong Answer

Solution code:
n = int(input())
dish = [list(map(int, input().split())) for i in range(n)]
sorted(dish, reverse=True)
turn = 1
a = 0
b = 0
for d in dish:
  if turn == 1:
    a += d[0]
    turn = 2
  else:
    b += d[1]
    turn =1

print(a-b)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = []#料理Nに対する高橋くんと青木さんの幸福度の和？
bs = 0#全ての料理を青木さんが食べたと仮定した時の青木さんの幸福度
for i in range(n):
    a,b = map(int,input().split())
    bs += b
    c.append(a+b)

c.sort()#Cを昇順ソート

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())
ab = [tuple(map(int, input().split())) for _ in range(n)]
a = sorted(range(n), key=lambda x: ab[x][1])
b = sorted(range(n), key=lambda x: ab[x][0])
v = set()
r = 0
while a:
    i = a.pop()
    if i not in v:
        r += ab[i][0]
        v.add(i)
        while b:
            i = b.pop()
            if i not in v:
                r -= ab[i][1]
                v.add(i)
                break
        
print(r)

Submission status: Wrong Answer

Solution code:
N, = [int(x) for x in input().split()]
A = [0]*N
B = [0]*N
C = [0]*N
for i in range(N):
  A[i], B[i] = [int(x) for x in input().split()]
  C[i] = A[i]-B[i]
jti = list(range(N))
jti.sort(key=lambda i: C[i])
print(sum([A[i] for i in jti[-1::-2]])-sum([B[i] for i in jti[-2::-2]]))

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)[::-1]:
  if i%2==0: ans += c[i]
    
print(ans)

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 reversed(range(n)):
  if i%2==0: ans += c[i]
    
print(ans)

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-1,-1,-1):
  if i%2==0: ans += c[i]
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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