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())
cuisine = [list(map(int,input().split())) for _ in range(N)]
max_point = sum(cuisine[0])
sort_cui = [cuisine[0]]
for i in range(1,N):
  check = sum(cuisine[i])
  if(check > max_point):
    sort_cui.insert(0, cuisine[i])
    max_point = check
  else:
    sort_cui.append(cuisine[i])
taka = 0
aoki = 0
ind = 0
for cui in sort_cui:
  if(ind%2 == 0):
    taka += cui[0]
  else:
    aoki += cui[1]
  ind += 1
print(taka - aoki)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

np_dif_list = np.array(dif_list)
dif_index_list = np.argsort(np_dif_list)

takahashi_score = 0
aoki_score = 0
for dish_index in dif_index_list:
    if dish_index % 2 == 0:
        takahashi_score += A_list[dish_index]
    else:
        aoki_score += B_list[dish_index]

print(takahashi_score - aoki_score)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
# import bisect
# import math
# import numpy as np


"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]


"""ここからメインコード"""


def main():
    # 1文字に省略
    ip = IP()

    """この下から書いてね"""
    n = ip.I()

    x = []
    y = []
    for i in range(n):
        x1, y1 = [int(i) for i in input().split()]
        x.append(x1)
        y.append(y1)
    x.sort()
    y.sort()
    y.pop(-1)
    y.append(0)
    y.sort()
    k = l = 0
    for i in range(n-1, -1, -2):
        k += x[i]
        l += y[i]
    print(k - l)


main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import numpy as np
n = int(input())

a = np.array([list(map(int,input().split())) for _ in range(n)])
a = np.sort(a)[::-1]
t = np.argsort(a[:,0]-a[:,1])

ans = 0

for i,j in zip(t,range(n)):
    if j%2 == 0:
        ans+=a[i][0]
    else:
        ans-=a[i][1]

print(ans)

Submission status: Wrong Answer

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

d = [(i, a - b, a, b) for i, (a, b) in enumerate(zip(A, B))]
dAB = sorted(d, key=lambda x: (x[1], x[2]), reverse=True)
dBA = sorted(d, key=lambda x: (x[1], -x[3]), reverse=True)

a_s = 0
b_s = 0
a_i = 0
b_i = N-1
i = 0
while True:
    if i & 1 == 0:
        a_s += A[dAB[a_i][0]]
        a_i += 1
        b_i -= 1
    else:
        b_s += B[dBA[b_i][0]]
        a_i += 1
        b_i -= 1
    if a_i >= N:
        break
    i += 1
print(a_s - b_s)

Submission status: Wrong Answer

Solution code:
def A():
    n, a, b = map(int, input().split())
    print(min(a, b), max(a + b - n, 0))
#A()

def B():
    N = int(input())
    A = input()
    B = input()
    C = input()
    cnt = 0
    ans = 0
    for i in range(N):
        cnt = 0
        if A[i] == B[i]:
            if B[i] == C[i]:
                cnt = cnt
            elif B[i] != C[i]:
                cnt += 1
        if A[i] != B[i]:
            if A[i] != C[i] and B[i] != C[i]:
                cnt += 3
            elif A[i] != C[i] and B[i] == C[i]:
                cnt += 1
            elif A[i] == C[i] and B[i] != C[i]:
                cnt += 1
        if cnt == 1:
            ans += 1
        elif cnt == 3:
            ans += 2

    print(ans)
#B()

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

    A.sort()
    B.sort()
    A = A[::-1]
    B = B[::-1]
    a = 0
    t = 0
    Aoki = 0
    Takahashi = 0
    check = [0 for i in range(N)]
    #print(A, B)
    for i in range(N):
        #print(a, t)
        while a < N:
            if check[A[a][3]] == 1:
                a += 1
            else:
                break

        while t < N:
            if check[B[t][3]] == 1:
                t += 1
            else:
                break

        if a < N and t < N:
            if A[a][2] > B[t][2]:
                Takahashi += A[a][0]
                check[A[a][3]] = 1
                a += 1
            else:
                Takahashi += B[t][1]
                check[B[t][3]] = 1
                t += 1
        else:
            if a < N:
                Takahashi += A[a][0]
                check[A[a][3]] = 1
                a += 1
            elif t < N:
                Takahashi += B[t][1]
                check[B[t][3]] = 1
                t += 1
            else:
                break
        #print(a, t, A[a], B[t])
        while a < N:
            if check[A[a][3]] == 1:
                a += 1
            else:
                break

        while t < N:
            if check[B[t][3]] == 1:
                t += 1
            else:
                break

        if a == N and t == N:
            break
            
        if a < N and t < N:
            if A[a][2] > B[t][2]:
                Aoki += A[a][1]
                check[A[a][3]] = 1
                a += 1
            else:
                Aoki += B[t][0]
                check[B[t][3]] = 1
                t += 1
        else:
            if a < N:
                Aoki += A[a][1]
                check[A[a][3]] = 1
                a += 1
            elif t < N:
                Aoki += B[t][0]
                check[B[t][3]] = 1
                t += 1


    print(Takahashi - Aoki)

C()

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())

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

diff = []
for _ in range(N):
    diff.append(B[_] - A[_])

diff = np.array(diff)
A = np.array(A)
B = np.array(B)

sort_index = diff.argsort()

A = (A[sort_index][::-1])
B = (B[sort_index][::-1])

taka = (A[0::2])
aoki = (B[1::2])

print(sum(taka) - sum(aoki))

Submission status: Wrong Answer

Solution code:
N = int(input())
tk = []
ak = []
bl = [False for _ in range(N)]  # 使われたか

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

tk.sort(key=lambda x: x[0], reverse=True)
ak.sort(key=lambda x: x[0], reverse=True)

ans = 0
c = 0
tk_i = 0
ak_i = 0
while c < N:
    while bl[tk_i]:
        tk_i += 1
    while bl[ak_i]:
        ak_i += 1
    if N - 1 == c:
        # 取るだけ
        if c % 2 == 0:
            # 高橋の番
            ans += tk[tk_i][0]
        else:
            # 青木の番
            ans -= ak[ak_i][0]
    else:
        if c % 2 == 0:
            # 高橋の番
            # 高橋最善、青木最善
            ak_ss_i = ak_i
            if tk[tk_i][1] == ak[ak_i][1]:  # 同じインデックスを狙っているとき
                ak_ss_i += 1
                while bl[ak_ss_i]:
                    ak_ss_i += 1
            ss = (tk[tk_i][0] - ak[ak_ss_i][0])
            # 青木の最善潰し、青木次善
            ak_tj_i = ak_i + 1
            while bl[ak_tj_i]:
                ak_tj_i += 1
            tj = (tk[ak_i][0] - ak[ak_tj_i][0])
            if ss >= tj:
                bl[tk_i] = True
                ans += tk[tk_i][0]
            else:
                bl[ak_i] = True
                ans += tk[ak_i][0]
        else:
            # 青木の番
            # 青木最善、高橋最善
            tk_ss_i = tk_i
            if ak[ak_i][1] == tk[tk_i][1]:  # 同じインデックスを狙っているとき
                tk_ss_i += 1
                while bl[tk_ss_i]:
                    tk_ss_i += 1
            ss = (ak[ak_i][0] - tk[tk_ss_i][0])
            # 高橋の最善潰し、高橋次善
            tk_tj_i = tk_i + 1
            while bl[tk_tj_i]:
                tk_tj_i += 1
            tj = (ak[tk_i][0] - tk[tk_tj_i][0])
            if ss >= tj:
                bl[ak_i] = True
                ans -= ak[ak_i][0]
            else:
                bl[tk_i] = True
                ans -= ak[tk_i][0]
    c += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
# import bisect
# import math
# import numpy as np


"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]


"""ここからメインコード"""


def main():
    # 1文字に省略
    ip = IP()

    """この下から書いてね"""
    n = ip.I()

    x = []
    y = []
    for i in range(n):
        x1, y1 = [int(i) for i in input().split()]
        x.append(x1)
        y.append(y1)
    x.sort()
    t = y[-1]
    y.pop(-1)
    y.append(t)
    y.sort()
    k = l = 0
    for i in range(n-1, -1, -2):
        k += x[i]
        l += y[i]
    print(k - l)


main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

N = int(input())

A = []
B = []
seen = [False] * N

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

A.sort()
B.sort()

sumA = 0
sumB = 0
while len(A) != 0 and len(B) != 0:
	while len(A) != 0 and seen[A[-1][2]]:
		try: A.pop()
		except: break
			
	try:
		sumA += A[-1][0]
		seen[A[-1][2]] = True
	except:
		pass
	
	while len(B) != 0 and seen[B[-1][2]]:
		try: B.pop()
		except: break
			
	try:
		sumB += B[-1][0]
		seen[B[-1][2]] = True
	except:
		pass
	

print(sumA - sumB)

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
AB=np.empty((N,2))
sum=np.empty(N)

for i in range(N):
    AB[i]=list(map(int,input().split()))
    sum[i]=AB[i][0]+AB[i][1]
lis = np.argsort(sum)[::-1]
taka=0
aoki=0
counter=0
for i in lis:
    if counter%2==0:
        taka+=AB[lis[i]][0]
    else:
        aoki+=AB[lis[i]][1]
    counter+=1
print(int(taka-aoki))

Submission status: Wrong Answer

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

taka = sorted(v, key=lambda x:x[0])
aoki = sorted(v, key=lambda x:x[1])
i = 0
t = 0
a = 0
while i < n:
    if i % 2 == 0:
        p, q = taka.pop()
        t += p
        aoki.remove((p, q))
    else:
        p, q = aoki.pop()
        a += q
        taka.remove((p, q))
    i += 1
print(t-a)

Submission status: Wrong Answer

Solution code:
from copy import copy

N = int(input())
A = []
B = []

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

A_orig = A[:]

diff = []

for i in range(N):
    diff.append(A[i]-B[i])
    
taka = 0
aoki = 0

for i in range(N):
    if i % 2==0:
        di = diff.index(max(diff))
        taka += A[di]
        diff.pop(di)
        A.pop(di)
        B.pop(di)
    else:
        di = diff.index(min(diff))
        aoki -= B[di]
        diff.pop(di)
        A.pop(di)
        B.pop(di)
    print(taka)
    print(aoki)

print(taka+aoki)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [long(input_raw[0])]
    A_list=[]
    B_list=[]
    All_list = []
    sum_list = []

    eated_set = set([])
    for i in range(N):
        input_raw = read_func().strip().split()
        [A, B] = [long(input_raw[0]), long(input_raw[1])]
        A_list.append(A)
        B_list.append(B)
        All_list.append((A, i))
        All_list.append((B, i))
        sum_list.append((A + B, i))

    All_list.sort(reverse = True)

    is_t_turn = True
    t_sum = 0L
    a_sum = 0L
    for i in range(len(All_list)):
        #if i in t_eated_set or i in a_eated_set:
        if All_list[i][1] in eated_set:
            continue
        if is_t_turn == True:
            t_sum += A_list[All_list[i][1]]

        else:
            a_sum += B_list[All_list[i][1]]

        eated_set.add(All_list[i][1])
        if is_t_turn == True:
            is_t_turn = False
        else:
            is_t_turn = True
    sum1 =  t_sum - a_sum

    is_t_turn = True
    t_sum = 0L
    a_sum = 0L
    eated_set = set([])
    sum_list.sort(reverse=True)
    for i in range(len(sum_list)):

        if is_t_turn == True:
            t_sum += A_list[sum_list[i][1]]

        else:
            a_sum += B_list[sum_list[i][1]]

        if is_t_turn == True:
            is_t_turn = False
        else:
            is_t_turn = True
    sum2 =  t_sum - a_sum

    print max(sum1, sum2)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
tlist=[]
alist=[]
dlist=[]

for i in range(0,N):
    t,a=map(int,input().split(" "))
    d=t-a
    tlist.append(t)
    alist.append(a)
    dlist.append(d)
#print(tlist,alist,dlist)

count=0
tscore=0
ascore=0
number=0

for count in range(0,N):
    if count%2==0:
        number=dlist.index(max(dlist))
        tscore+=tlist[number]
    else:
        number=dlist.index(min(dlist))
        ascore+=alist[number]

    #print(tscore,ascore)
    del tlist[number]
    del alist[number]
    del dlist[number]      

print(tscore-ascore)

Submission status: Wrong Answer

Solution code:
N = int(input())
tk = []
ak = []
bl = [False for _ in range(N)]  # 使われたか

for i in range(1, N + 1):
    a, b = map(int, input().split())
    tk.append((a, i))
    ak.append((b, i))

tk.sort(key=lambda x: x[0], reverse=True)
ak.sort(key=lambda x: x[0], reverse=True)

ans = 0
c = 0
tk_i = 0
ak_i = 0
while c < N:
    while bl[tk_i]:
        tk_i += 1
    while bl[ak_i]:
        ak_i += 1
    if N - 1 == c:
        # 取るだけ
        if c % 2 == 0:
            # 高橋の番
            ans += tk[tk_i][0]
        else:
            # 青木の番
            ans -= ak[ak_i][0]
    else:
        if c % 2 == 0:
            # 高橋の番
            # 高橋最善、青木最善
            ak_ss_i = ak_i
            if tk[tk_i][1] == ak[ak_i][1]:  # 同じインデックスを狙っているとき
                ak_ss_i += 1
                while bl[ak_ss_i]:
                    ak_ss_i += 1
            ss = (tk[tk_i][0] - ak[ak_ss_i][0])
            # 青木の最善潰し、青木次善
            ak_tj_i = ak_i + 1
            while bl[ak_tj_i]:
                ak_tj_i += 1
            tj = (tk[ak_i][0] - ak[ak_tj_i][0])
            if ss >= tj:
                bl[tk_i] = True
                ans += tk[tk_i][0]
            else:
                bl[ak_i] = True
                ans += tk[ak_i][0]
        else:
            # 青木の番
            # 青木最善、高橋最善
            tk_ss_i = tk_i
            if ak[ak_i][1] == tk[tk_i][1]:  # 同じインデックスを狙っているとき
                tk_ss_i += 1
                while bl[tk_ss_i]:
                    tk_ss_i += 1
            ss = (ak[ak_i][0] - tk[tk_ss_i][0])
            # 高橋の最善潰し、高橋次善
            tk_tj_i = tk_i + 1
            while bl[tk_tj_i]:
                tk_tj_i += 1
            tj = (ak[tk_i][0] - tk[tk_tj_i][0])
            if ss >= tj:
                bl[ak_i] = True
                ans -= ak[ak_i][0]
            else:
                bl[tk_i] = True
                ans -= ak[tk_i][0]
    c += 1
print(ans)

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())
    diff = a-b
    D.append([diff,i])
    A.append(a)
    B.append(b)
else:
    D.sort()

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

Submission status: Wrong Answer

Solution code:
from collections import deque
n =int(input())
a = []
takahashi = 0
aoki = 0
for i in range(n):
 tmp1,tmp2 = (int(i) for i in input().split())
 a.append([tmp1,tmp2])
a2 = sorted(a, key=lambda x: x[0])
a3 = sorted(a, key=lambda x: x[1])
d = deque(a2)
d2 = deque(a3)
start = 0
for i in range(n):
 if start%2 == 0:
  a,b =d.pop()
  d2.remove([a,b])
  takahashi += a
  #print(d)
 if start %2 == 1:
  a,b = d2.pop()
  d.remove([a,b])
  aoki += b
  #print(d)
 start += 1
print(takahashi -aoki)

Submission status: Wrong Answer

Solution code:
def A():
    n, a, b = map(int, input().split())
    print(min(a, b), max(a + b - n, 0))
#A()

def B():
    N = int(input())
    A = input()
    B = input()
    C = input()
    cnt = 0
    ans = 0
    for i in range(N):
        cnt = 0
        if A[i] == B[i]:
            if B[i] == C[i]:
                cnt = cnt
            elif B[i] != C[i]:
                cnt += 1
        if A[i] != B[i]:
            if A[i] != C[i] and B[i] != C[i]:
                cnt += 3
            elif A[i] != C[i] and B[i] == C[i]:
                cnt += 1
            elif A[i] == C[i] and B[i] != C[i]:
                cnt += 1
        if cnt == 1:
            ans += 1
        elif cnt == 3:
            ans += 2

    print(ans)
#B()

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

    A.sort()
    B.sort()
    A = A[::-1]
    B = B[::-1]
    a = 0
    t = 0
    Aoki = 0
    Takahashi = 0
    check = [0 for i in range(N)]
    #print(A, B)
    for i in range(N):
        #print(a, t)
        while a < N:
            if check[A[a][3]] == 1:
                a += 1
            else:
                break

        while t < N:
            if check[B[t][3]] == 1 and t < N:
                t += 1
            else:
                break

        if a < N and t < N:
            if A[a][2] > B[t][2]:
                Takahashi += A[a][0]
                check[A[a][3]] = 1
                a += 1
            else:
                Takahashi += B[t][1]
                check[B[t][3]] = 1
                t += 1
        else:
            if a < N:
                Takahashi += A[a][0]
                check[A[a][3]] = 1
            elif t < N:
                Takahashi += B[t][1]
                check[B[t][3]] = 1
                t += 1
            else:
                break
        #print(a, t, A[a], B[t])
        while a < N:
            if check[A[a][3]] == 1:
                a += 1
            else:
                break

        while t < N:
            if check[B[t][3]] == 1 and t < N:
                t += 1
            else:
                break

        if a == N and t == N:
            break
        if a < N and t < N:
            if A[a][2] > B[t][2]:
                Aoki += A[a][1]
                check[A[a][3]] = 1
                a += 1
            else:
                Aoki += B[t][0]
                check[B[t][3]] = 1
                t += 1
        else:
            if a < N:
                Aoki += A[a][1]
                check[A[a][3]] = 1
            elif t < N:
                Aoki += B[t][0]
                check[B[t][3]] = 1
                t += 1


    print(Takahashi - Aoki)

C()

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, i))
    B.append((b, i))

OA = A[:]
OB = B[:]
A.sort(key=lambda x:x[0])
B.sort(key=lambda x:x[0])


used = [False]*N
x, y = 0, 0
for _ in range(N):
    while A:
        ai, i = A[-1]
        bi, i = OB[i]
        if used[i]:
            A.pop()
            continue
        bj, j = B[-1]
        aj, j = OA[j]
        if used[j]:
            B.pop()
            continue
        if _ % 2 == 0:
            if (ai - bi) > (aj - bj):
                x += ai
                used[i] = True
                A.pop()
            else:
                x += OA[j][0]
                used[j] = True
                B.pop()
        else:
            if (bj - aj) > (bi - ai):
                y += bj 
                used[j] = True
                B.pop()
            else:
                y += OB[i][0]
                used[i] = True
                A.pop()
        break
print(x - y)

Submission status: Wrong Answer

Solution code:
import math
from operator import itemgetter

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

C = [(A[i], B[i]) for i in range(N)]
C = sorted(C, key=itemgetter(1), reverse=True)
C = sorted(C, key=itemgetter(0), reverse=True)

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []
B = []
for i in range(n):
    a, b = tuple(map(int, input().split(' ')))

    A.append(a)
    B.append(b)

eaten_dishes = set()

def taka_select():
    max_choice = None
    happiness = 0
    opponent_happiness = 0
    for i in range(n):
        if i in eaten_dishes:
            continue
        if max_choice == None:
            max_choice = i
            happiness = A[i]
            opponent_happiness = B[i]
        elif A[i] > happiness:
            max_choice = i
            happiness = A[i]
            opponent_happiness = B[i]
        elif A[i] == happiness and B[i] > opponent_happiness:
            max_choice = i
            happiness = A[i]
            opponent_happiness = B[i]

    return max_choice, happiness

def aoki_select():
    max_choice = None
    happiness = 0
    opponent_happiness = 0
    for i in range(n):
        if i in eaten_dishes:
            continue
        if max_choice == None:
            max_choice = i
            happiness = B[i]
            opponent_happiness = A[i]
        elif B[i] > happiness:
            max_choice = i
            happiness = B[i]
            opponent_happiness = A[i]
        elif B[i] == happiness and A[i] > opponent_happiness:
            max_choice = i
            happiness = B[i]
            opponent_happiness = A[i]
    return max_choice, happiness

total = 0
for i in range(n):
    # aoki turn
    select, happiness = (0, 0)
    if i % 2 == 0:
        select, happiness = taka_select()
        total += happiness
    else:
        select, happiness = aoki_select()
        total -= happiness
    eaten_dishes.add(select)
    print(select, happiness)

print(total)

Submission status: Wrong Answer

Solution code:
N=int(input())
AB=[list(map(int,input().split())) for i in range(N)]
AB.sort(key = lambda l:(l[1], l[0]), reverse=True)
takahashi=0
aoki=0
for i in range(N):
    if i%2==0:
        takahashi+=AB[i][0]
    else:
        aoki+=AB[i][1]
print(takahashi-aoki)

Submission status: Wrong Answer

Solution code:
N = int(input())
happiness = []

for n in range(N):
    num = input().split()
    a = int(num[0])
    b = int(num[1])
    happiness.append([a + b, a, b])

happiness.reverse()

sumA = 0
sumB = 0
turn = 0

for n in range(N):
    if turn == 0:
        sumA += happiness[n][1]
    else:
        sumB += happiness[n][2]
    turn ^= 1

print(sumA - sumB)

Submission status: Wrong Answer

Solution code:
n = int(input())
res = [0 for i in range(n)]
for j in range(n):
    a, b = (int(i) for i in input().split())
    res[j] = a-b
tak = 0
she = 0
res = sorted(res)[::-1]
for i in range(n):
    if i & 1 == 1:
        she += abs(res[i])
    else:
        tak += abs(res[i])
print(abs(she-tak))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
C = []
A,B = [],[]
for i in range(N):
    a,b = list(map(int,input().split()))
    A.append(a)
    B.append(b)
    # print("A,B:",A,B)



# print(C)

arrA,arrB = np.array(A).astype(np.int64),np.array(B).astype(np.int64)
minA,minB = arrA.min(),arrB.min()
diffA = arrA -minA
diffB = arrB -minB
# print(diffA)
C = np.array([max(a,b) for a,b in zip(diffA,diffB)])

ordC = np.argsort(C)[::-1]
# print(ordC)
# print(arrA[ordC][::2])
# print(arrB[ordC][1::2])
print(sum(arrA[ordC][::2]) - sum(arrB[ordC][1::2]))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())

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

diff = []
for _ in range(N):
    diff.append(B[_] - A[_])

diff = np.array(diff)
A = np.array(A)
B = np.array(B)

sort_index = diff.argsort()

A = (A[sort_index])
B = (B[sort_index])

if N%2 == 0:
    taka = (A[1::2])
    aoki = (B[2::2])
else:
    taka = (A[0::2])
    aoki = (B[1::2])

print(sum(taka) - sum(aoki))

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, i))
    B.append((b, i))

OA = A[:]
OB = B[:]
A.sort(key=lambda x:x[0])
B.sort(key=lambda x:x[0])


used = [False]*N
x, y = 0, 0
for _ in range(N):
    while A:
        ai, i = A[-1]
        bi, i = OB[i]
        if used[i]:
            A.pop()
            continue
        bj, j = B[-1]
        aj, j = OA[j]
        if used[j]:
            B.pop()
            continue
        if _ % 2 == 0:
            if (ai - bi) > (aj - bj):
                x += ai
                used[i] = True
                A.pop()
            else:
                x += OA[j][0]
                used[j] = True
                B.pop()
        else:
            if (bi - ai) > (bj - aj):
                y += bj 
                used[j] = True
                B.pop()
            else:
                y += OB[i][0]
                used[i] = True
                A.pop()
        break
print(x - y)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [None] * N
B = [None] * N
L = list(range(N))
F = [False] * N

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

P = 0
Q = 0

T = True

C    = zip(A, B, L)
C    = sorted(C, key=lambda x: [x[0], x[1]], reverse=True)
D    = zip(B, A, L)
D    = sorted(D, key=lambda x: [x[0], x[1]], reverse=True)

C_A, C_B, C_L = map(list, zip(*C))
D_B, D_A, D_L = map(list, zip(*D))

i_A = 0
i_B = 0

for _ in range(N):
    if T:
        for i in range(i_A, len(C_L)):
            if F[C_L[i]] == False:
                P        += C_A[i]
                F[C_L[i]] = True
                T         = False
                i_A       = i
                break
    else:
        for i in range(i_B, len(D_L)):
            if F[D_L[i]] == False:
                Q        += D_B[i]
                F[D_L[i]] = True
                T         = True
                i_B       = i
                break

print(P-Q)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = 0
b = 0
c = 0
d = 0
for i in range(n):
    x, y = map(int, input().split())
    if i%2:
        a += x
        c += y
    else:
        b += x
        d += y
print(max((a-d), (b-c)))

Submission status: Wrong Answer

Solution code:
N=int(input())
AB=[list(map(int,input().split())) for i in range(N)]
AB.sort(key = lambda l:(l[0], l[1]), reverse=True)
takahashi=0
aoki=0
for i in range(N):
    if i%2==0:
        takahashi+=AB[i][0]
    else:
        aoki+=AB[i][1]
print(takahashi-aoki)