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:
# coding: utf-8
N = int(input())
A = {x: [] for x in range(N)}
B = {x: [] for x in range(N)}
n_set = set([i for i in range(N)])
total = 0
for i in range(N):
    a, b = list(map(int, input().split()))
    A[i] = [a, b]
    B[i] = [b, a]
A_list = sorted(A.items(), key=lambda x: (x[1][0],x[1][1]), reverse=True)
B_list = sorted(B.items(), key=lambda x: (x[1][0],x[1][1]), reverse=True)

i, j = 0, 0
while n_set:
    if A_list[i][0] in n_set:
        total += A_list[i][1][0]
        n_set.discard(A_list[i][0])
        i += 1
    else:
        i += 1
        continue
    if not n_set:
        break
    if B_list[j][0] in n_set:
        total -= B_list[j][1][0]
        n_set.discard(B_list[j][0])
        j += 1
    else:
        while True:
            j += 1
            if B_list[j][0] in n_set:
                total -= B_list[j][1][0]
                n_set.discard(B_list[j][0])
                j += 1
                break
print(total)

Submission status: Wrong Answer

Solution code:
import numpy as np


def _main():
    N = int(input())
    AB = np.empty((2, N), dtype=np.int64)
    for i in range(N):
        AB[:, i] = list(map(int, input().split()))
    AB_sorted = AB.argsort(axis=-1)
    sorted_tops = [N - 1, N - 1]

    scores = [0, 0]  # 高橋くん, 青木さん
    food_exists = np.ones((N,), dtype=bool)
    turn = 0
    for _ in range(N):
        turN = turn ^ 1
        max1 = AB_sorted[turn, sorted_tops[turn]]
        max2 = AB_sorted[turN, sorted_tops[turN]]
        if AB[turn, max1] > AB[turN, max2]:
            eat = max1
            food_exists[eat] = False
            sorted_tops[turn] -= 1
        else:
            eat = max2
            food_exists[eat] = False
            sorted_tops[turN] -= 1

        for t in range(2):
            while 0 < sorted_tops[t]:
                if food_exists[AB_sorted[t, sorted_tops[t]]]:
                    break
                sorted_tops[t] -= 1

        scores[turn] += int(AB[turn, eat])
        turn ^= 1

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


if __name__ == '__main__':
    _main()

Submission status: Wrong Answer

Solution code:
N=int(input())
#dish=[]
X_=[]
Y_=[]
xp=0
yp=0
for i in range(N):
    a=list(input().split())
    A,B=int(a[0]),int(a[1])
    #dish.append([A,B])
    X_.append(A-B)
#print(X_)

for i in range(N):
    if i %2==0:
        XM=min(X_)
        xp+=abs(XM)
        X_.remove(XM)
    elif i %2==1:
        YM=min(X_)
        yp+=abs(YM)
        X_.remove(YM)
        
        
print(xp-yp)

Submission status: Wrong Answer

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

check = [False for _ in range(N)]

taka = []

for i in range(N):
    _, a, b = ab[i]
    if a >= b:
        taka.append((i, a, b, a))
    else:
        taka.append((i, b, b, a))
aoki = []
for i in range(N):
    _, a, b = ab[i]
    if b >= a:
        aoki.append((i, b, a, b))
    else:
        aoki.append((i, a, a, b))

taka = sorted(taka, key=lambda x:(-x[1], -x[2], -x[3]))
aoki = sorted(aoki, key=lambda x:(-x[1], -x[2], -x[3]))

ans = 0
i = 0
j = 0
for k in range(N):
    if k % 2 == 0:
        t = taka[i]
        while check[t[0]]:
            i += 1
            t = taka[i]
        ans += t[3]
        check[t[0]] = True
        i += 1
    else:
        a = aoki[j]
        while check[a[0]]:
            j += 1
            a = aoki[j]
        ans -= a[3]
        check[a[0]] = True
        j += 1
print(ans)

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)
taka=0
aoki=0
for i in lis:
    if N%2==0:
        if i%2!=0:
            taka+=AB[lis[i]][0]
        else:
            i=AB[lis[i]][1]
    else:
        if i%2==0:
            taka+=AB[lis[i]][0]
        else:
            i=AB[lis[i]][1]

print(int(taka-aoki))

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
from operator import itemgetter
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
l = []
for i in range(N):
    a,b = IL()
    l.append([a,b,a/b])

l.sort(key=itemgetter(2))

chokudai = 0
aoki = 0
for i in range(N):
    if i%2 == 0:
        chokudai += l[i][0]
    else:
        aoki += l[i][1]

print(chokudai-aoki)

Submission status: Wrong Answer

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

li2 = sorted(li, key=lambda x: (x[0] - x[1]), reverse=True)
v = 0
for i, (a, b) in enumerate(li2):
    if i % 2 == 0:
        v += a
    else:
        v -= b

print(v)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [[] for i in range(n)]
A, B = 0, 0
for i in range(n):
    l[i] = list(map(int, input().split()))
    l[i].append(l[i][0]-l[i][1])
l.sort(key = lambda x: (x[2], -x[0], -x[1]))
for i in range(n):
    if(i%2 == 0):
        #print(l)
        A += l[i][0]
    else:
        pnt = l[i][2]
        j = 0
        flag = 0
        #print(i, j)
        while  i+j < n:
            if(pnt != l[i+j][2]): break
            if(l[i][1] < l[i+j][1]):
                l.sort(key = lambda x: (x[2], -x[1], -x[0]))
                #print(l)
                flag = 1
                break
            j+=1
        if(flag == 1): l.sort(key = lambda x: (x[2], -x[0], -x[1]))
        B += l[i][1]
print(A - B)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np

N = int(input())
aList = []
bList = []
sa =[]
for i in range(N):
  a,b = map(int, stdin.readline().rstrip().split())
  aList.append(a)
  bList.append(b)
  sa.append(a-b)

sa=np.array(sa)
sa = np.sort(sa)
saIndex=np.argsort(sa)

score = 0
for i in range (N):
  if i % 2==0:
    score += aList[saIndex[i]]
  else:
    score -= bList[saIndex[i]]

print(score)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    c = []
    d = []
    e = []
    
    for i in range(0, n):
        a, b = map(int, input().split())
        c.append(a)
        d.append(b)
        e.append(abs(a - b))
    
    li1, li2 = sorted(e), sorted(range(len(e)), key=lambda k: e[k])
    
    turn = 0
    happy = 0

    for i in range(n - 1, -1, -1):
        if (turn == 0):
            happy += c[li2[i]]
        else:
            happy -= d[li2[i]]
        turn = (turn + 1) % 2
    print(happy)

Submission status: Wrong Answer

Solution code:
N=int(input())

Takahashi=[]
Aoki=[]

for i in range(N):
  A,B=map(int,input().split())
  if A>B:
    symbol='p'
  else:
    symbol='m'
  Takahashi.append([abs(A-B),B,i,A])
  Aoki.append([abs(B-A),A,i,B])

Takahashi=sorted(Takahashi,key=lambda x: (x[0],x[1]),reverse=True)
Aoki=sorted(Aoki,key=lambda x: (x[0],x[1]),reverse=True)

#print(Takahashi)

turn=0
Asum=0
Bsum=0
while Takahashi:
  if turn%2==0:
    Asum+=Takahashi[0][3]
    index=Takahashi[0][2]
    Takahashi.pop(0)
    for i in range(len(Aoki)):
      if index==Aoki[i][2]:
        del Aoki[i]
        break
  else:
    Bsum+=Aoki[0][3]
    index=Aoki[0][2]
    Aoki.pop(0)
    for i in range(len(Takahashi)):
      if index==Takahashi[i][2]:
        del Takahashi[i]
        break
  
  turn+=1
  #print(Takahashi)
  #print(Aoki)
print(Asum-Bsum)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

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

taka = 0
aoki = 0
for i, c in enumerate(Cs):
    if i % 2 == 0:
        taka += Cs[i][1]
    else:
        aoki += Cs[i][2]
print(taka - aoki)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
b = sorted([[a[i][0] - a[i][1], a[i][0]] for i in range(n)])
taka = 0
aoki = 0
k = 0

for i in range(n):
  if i % 2 == 0:
    taka += b[n - k - i - 1][1]
  else:
    aoki += b[n - k - i - 1][1] - b[n - k - i - 1][0]

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 = []
    abs_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))
        abs_list.append((abs(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

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

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

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

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

    print max(sum1, sum2, sum3)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    c = []
    d = []
    e = []
    
    for i in range(0, n):
        a, b = map(int, input().split())
        c.append(a)
        d.append(b)
        e.append(abs(a - b))
    
    li1, li2 = sorted(e), sorted(range(len(e)), key=lambda k: e[k])
    
    turn = 0
    happy = 0

    for i in range(n - 1, -1, -1):
        if (turn == 0):
            happy += c[li2[i]]
        else:
            happy -= d[li2[i]]
        print(happy)
        turn = (turn + 1) % 2
    print(happy)

Submission status: Wrong Answer

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

check = [False for _ in range(N)]

taka = []

for i in range(N):
    _, a, b = ab[i]
    if a >= b:
        taka.append((i, a, a, b))
    else:
        taka.append((i, b, a, b))
aoki = []
for i in range(N):
    _, a, b = ab[i]
    if b >= a:
        aoki.append((i, b, b, a))
    else:
        aoki.append((i, a, b, a))

taka = sorted(taka, key=lambda x:(-x[1], -x[2], -x[3]))
aoki = sorted(aoki, key=lambda x:(-x[1], -x[2], -x[3]))

ans = 0
i = 0
j = 0
for k in range(N):
    if k % 2 == 0:
        t = taka[i]
        while check[t[0]]:
            i += 1
            t = taka[i]
        ans += t[2]
        check[t[0]] = True
        i += 1
    else:
        a = aoki[j]
        while check[a[0]]:
            j += 1
            a = aoki[j]
        ans -= a[2]
        check[a[0]] = True
        j += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [[0]*3 for i in range(n)]
for i in range(n):
    a,b = map(int,input().split())	
    x[i] = [a+b,a,b]
x.sort()
A = 0
T = 0
for i in range(n):
    if i%2 == 0:
        A+=x[i][1]
    else:
        T+=x[i][2]
print(A-T)

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)

takahashi = list(sorted(range(n), key=lambda dish: (b[dish], a[dish])))
aoki = list(sorted(range(n), key=lambda dish: (a[dish], b[dish])))

who = True
history = set()
i = j = x = y = 0
for _ in range(n):
    if who:
        while True:
            i = takahashi.pop()
            if i in history: continue
            x += a[i]
            history.add(i)
            break
    else:
        while True:
            i = aoki.pop()
            if i in history: continue
            y += b[i]
            history.add(i)
            break
    who = not who

print(x - y)

Submission status: Wrong Answer

Solution code:
N = int( input())
A = [0]*N
B = [0]*N
C = [0]*N
SA = [(0,0)]*N
SB = [(0,0)]*N
for i in range(N):
    a, b = map( int, input().split())
    A[i] = a
    B[i] = b
    SA[i] = (-a,-b,i)
    SB[i] = (-b,-a,i)
SA.sort()
SB.sort()
ansa = 0
ansb = 0
a = 0
b = 0
for i in range(N):
    if i%2 == 0:
        while 1:
           _, _,j = SA[a]
           if C[j] == 0:
                ansa += A[j]
                C[j] = 1
                a += 1
                break
           else:
                a += 1
    else:
        while 1:
            _,_,j = SB[b]
            if C[j] == 0:
                ansb += B[j]
                C[j] = 1
                b += 1
                break
            else:
                b += 1
print( ansa - ansb)

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 = a[np.argsort(a[:,0],axis=0)[::-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:
#coding:utf-8 
###### input ######
n = int(input())
taka = []
aoki = []
for i in range(n):
  t,a= map(int,input().split())
  taka.append(t)
  aoki.append(a)
 
###### main ######
res = 0
for i in range(n):
  if max(taka) < max(aoki):
    tmp = aoki.index(max(aoki))#[0]
  else:
    tmp = taka.index(max(taka))#[0]
  
  if i % 2 == 0:
    res += taka[tmp]
  else:
    res -= aoki[tmp]
 
  taka[tmp] = 0
  aoki[tmp] = 0
 
print(res)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n = int(input())
ab = []
a = []
b = []
flag = 0
for _ in range(n):
    tmp = list(map(int, input().split()))
    ab.append(tmp)
while True:
    if flag == 0:
        flag = 1
        ab.sort(reverse=True, key=itemgetter(0))
        a.append(ab.pop(0)[0])
    else:
        flag = 0
        ab.sort(reverse=True, key=itemgetter(1))
        b.append(ab.pop(0)[1])
    if len(ab) == 0:
        break
print(sum(a) - sum(b))

Submission status: Wrong Answer

Solution code:
n = int(input())
z = [[int(x) for x in input().split()] for i in range(n)]
z.sort(reverse=True)

a = []
b = []
for i in range(n // 2):
    a.append(z[2 * i][0])
    b.append(z[2 * i + 1][1])
if n % 2 == 1:
    a.append(z[len(z) - 1][0])

print(sum(a) - sum(b))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter, attrgetter

taka = 0
ao = 0

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

for i, temp in enumerate(string_list):
  string_list[i].append(string_list[i][0] - string_list[i][1])

temp = sorted(string_list, key=itemgetter(2))

for i, temp in enumerate(temp):
  if i % 2 == 0:
    taka += temp[0]
  else:
    ao += temp[1]

print(taka - ao)

Submission status: Wrong Answer

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

lst.sort(key=lambda x:(x[2],x[1],x[0]), reverse=True)
#print(lst)

count = 1
Takahashi = 0
Aoki = 0
for i in lst:
    if count % 2 == 1:
        Takahashi += i[0]
    else:
        Aoki += i[1]
    count+=1
print(Takahashi-Aoki)

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = [[]]*N
for i in range(N):
    AB[i] = list(map(int, input().split()))

AB.sort(reverse=True)

point_t = 0
point_a = 0
flg = True
for j in range(N):
    if flg:
        point_t += AB[j][0]
        flg = False
    else:
        point_a += AB[j][1]
        flg = True
print(point_t - point_a)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np

N = int(input())
aList = []
bList = []
sa =[]
for i in range(N):
  a,b = map(int, stdin.readline().rstrip().split())
  aList.append(a)
  bList.append(b)
  sa.append(a-b)

sa=np.array(sa)
sa = np.sort(sa)[-1::-1]
saIndex=np.argsort(sa)

score = 0
for i in range (N):
  if i % 2==0:
    score += aList[saIndex[i]]
  else:
    score -= bList[saIndex[i]]

print(score)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = []
for i in range(N):
    a, b = map(int, input().split())
    D.append((a + b, a, b))
D.sort()
res = 0
for i, (_, a, b) in enumerate(D):
    if i % 2 == 0:
        res += a
    else:
        res -= b
print(res)

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 and B:
        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 - bj) >= (aj - bi):
                x += ai
                used[i] = True
                A.pop()
            else:
                x += OA[j][0]
                used[j] = True
                B.pop()
        else:
            if (bj - ai) >= (bi - 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 = input()

data = []

for i in range(N):
    A,B = map(int,raw_input().split())
    C = min(A-B,A)
    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())
ab = []
for i in range(N):
    a, b = map(int, input().split())
    ab.append((i, a, b))

check = [False for _ in range(N)]

taka = []

for i in range(N):
    _, a, b = ab[i]
    if a >= b:
        taka.append((i, a, a))
    else:
        taka.append((i, b, a))
aoki = []
for i in range(N):
    _, a, b = ab[i]
    if b >= a:
        aoki.append((i, b, b))
    else:
        aoki.append((i, a, b))

taka = sorted(taka, key=lambda x:(-x[1], -x[2]))
aoki = sorted(aoki, key=lambda x:(-x[1], -x[2]))

ans = 0
i = 0
j = 0
for k in range(N):
    if k % 2 == 0:
        t = taka[i]
        while check[t[0]]:
            i += 1
            t = taka[i]
        ans += t[2]
        check[t[0]] = True
        i += 1
    else:
        a = aoki[j]
        while check[a[0]]:
            j += 1
            a = aoki[j]
        ans -= a[2]
        check[a[0]] = True
        j += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
Alist = []
Blist = []
sumlist = []

for i in range(N):
    a,b = map(int,input().split())
    Alist.append(a)
    Blist.append(b)
    sumlist.append(a+b)

sumlist = np.sort(sumlist)
sumlist = sumlist[-1::-1]
index = np.argsort(sumlist)
index = index[-1::-1]
counter = 0
takahasi = 0
aoki = 0

for i in range(N):
    if counter == 0:
        takahasi += Alist[index[i]]
        sumlist[i] = 0
        counter = 1
        continue
    if counter == 1:
        aoki += Blist[index[i]]
        sumlist[i] = 0
        counter = 0
        continue

print(takahasi-aoki)

Submission status: Wrong Answer

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

rec = sorted(rec, key=lambda x: x[1], reverse=True)
rec = sorted(rec, key=lambda x: x[0], reverse=True)
num = 0
for i in range(N):
    if i % 2 == 0:
        num += rec[i][0]
    else:
        num -= rec[i][1]

print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
su = []
for i in range(N):
    a, b = (int(i) for i in input().split())
    A.append(a)
    B.append(b)
    su.append( (a + b, a - b, a, b) )
su.sort()
su.reverse()

cc = 0
for i in range(N):
    if i < N-1 and su[i][0] == su[i+1][0]:
        cc += 1
    else:
        if cc:
            temp = []
            for j in range(i-cc, i+1):
                temp.append(su[j])
            temp2 = []
            for j in range(i-cc, i+1):
                if j % 2 == 0:
                    temp2.append(temp.pop(0))
                else:
                    temp2.append(temp.pop())
            for j in range(i-cc, i+1):
                su[j] = temp2[j-(i-cc)]
            cc = 0
ans = 0
print(su)
for i in range(N):
    if i%2 == 0:
        ans += su[i][2]
    else:
        ans -= su[i][3]

print(ans)

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 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 and B:
        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:
N = int(input())
lst =[]
#lst = [list(map(int,input().split())) for i in range(N)]
for i in range(N):
    a,b = map(int,input().split())
    lst.append([a,b,b-a])

lst.sort(key=lambda x:(x[2],x[1],x[0]), reverse=True)
#print(lst)

count = 1
Takahashi = 0
Aoki = 0
for i in lst:
    if count % 2 == 1:
        Takahashi += i[0]
    else:
        Aoki += i[1]
    count+=1
print(Takahashi-Aoki)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(raw_input())

score_table=[]
for i in range(N):
	score_table.append(map(int, raw_input().split()))
#print score_table

score_sub =[]
for i in range(N):
	score_table[i].append(score_table[i][0]-score_table[i][1])

#print score_table

score_table.sort(key=itemgetter(2))
#print score_table


total_score = 0
odd_flag = 0
for a,b,sub in score_table:
	if not odd_flag%2:
		total_score += a
	else:
		total_score -= b
	odd_flag += 1
print total_score

Submission status: Wrong Answer

Solution code:
from collections import deque
n =int(input())
takahashi = 0
aoki = 0
a = [[int(i) for i in input().split()] for i in range(n)] 
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:
N = input()

data = []

for i in range(N):
    A,B = map(int,raw_input().split())
    C = min(A-B,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:
#coding:utf-8

###### input ######
n = int(input())
taka = []
aoki = []
for i in range(n):
  t,a= map(int,input().split())
  taka.append(t)
  aoki.append(a)

###### main ######
res = 0
for i in range(n):
  if max(taka) < max(aoki):
    tmp = aoki.index(max(aoki))#[0]
  else:
    tmp = taka.index(max(taka))#[0]
  
  if i % 2 == 0:
    res+= taka[tmp]
  else:
    res -= aoki[tmp]

  taka[tmp] = 0
  aoki[tmp] = 0

print(res)

Submission status: Wrong Answer

Solution code:
import numpy as np


def _main():
    N = int(input())
    AB = np.empty((2, N), dtype=np.int64)
    for i in range(N):
        AB[:, i] = list(map(int, input().split()))
    AB_sorted = AB.argsort(axis=-1)
    sorted_tops = [N - 1, N - 1]

    scores = [0, 0]  # 高橋くん, 青木さん
    food_exists = np.ones((N,), dtype=bool)
    turn = 0
    for _ in range(N):
        turN = turn ^ 1
        max1 = AB_sorted[turn, sorted_tops[turn]]
        max2 = AB_sorted[turN, sorted_tops[turN]]
        assert food_exists[max1] and food_exists[max2]
        if AB[turn, max1] >= AB[turN, max2]:
            eat = max1
            food_exists[eat] = False
            sorted_tops[turn] -= 1
        else:
            eat = max2
            food_exists[eat] = False
            sorted_tops[turN] -= 1

        for t in range(2):
            while 0 < sorted_tops[t]:
                if food_exists[AB_sorted[t, sorted_tops[t]]]:
                    break
                sorted_tops[t] -= 1

        scores[turn] += AB[turn, eat]

        turn ^= 1

    print(np.int64(scores[0] - scores[1]))


if __name__ == '__main__':
    _main()