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:
import sys

import numpy as np

sys.setrecursionlimit(200000)


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


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


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


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


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


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


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

Submission status: Wrong Answer

Solution code:
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))
b=copy.deepcopy(a)





def akey(a):
    return a[0],a[1]
def bkey(a):
    return a[1],a[0]
list.sort(a,key=akey,reverse=True)
list.sort(b,key=bkey,reverse=True)

def remove(a, data,tag):
    if tag:
        tag=0
    else:
        tag=1
    n = len(a)
    first = 0
    last = n - 1

    while first <= last:
        mid = int(first + ((last - first) / 2))

        if a[mid][tag] < data[tag]:
            last = mid - 1
        elif a[mid][tag] > data[tag]:
            first = mid + 1
        else:
            del a[mid]
            return

def func(a,b):
    pa,pb=0,0
    tag=True
    while len(a)!=0:

        
        if a[0]==b[0]:
            tmp=a[0]
        else:
            v1=a[0][0]-b[0][1]
            v2=b[0][0]-b[1][1]
            if v1>v2:
                tmp=a[0]
            else:
                tmp=b[0]
        if tag:
            pa+=tmp[0]
        else:
            pb+=tmp[1]

        remove(a,tmp,tag)
        remove(b,tmp,tag)
        tag=not tag
        a,b=b,a

    return pa-pb
    
print(func(a,b))

Submission status: Wrong Answer

Solution code:
N=int(raw_input())
S=[[0,0]for i in range(N)]
notused=[1 for i in range(N)]
for i in range(N):
    A,B=[int(x) for x in raw_input().split()]
    S[i]=[A,B,i]
SA=sorted( sorted(S,key=lambda x:x[1], reverse=True), key=lambda x:x[0], reverse=True)
SB=sorted( sorted(S,key=lambda x:x[0],reverse=True), key=lambda x:x[1],reverse=True)
ans=0
tturn=1
aind=0
bind=0
for i in range(N):
    if SA[aind][0]>=SB[bind][1]:
        chosen=SA[aind][2]
        notused[chosen]=0
    else:
        chosen=SB[bind][2]
        notused[chosen]=0
    while( notused[ SA[aind][2] ]==0):
        aind+=1
        if aind==N:
            break
    while( notused[ SB[bind][2] ]==0):
        bind+=1
        if bind==N:
            break
    if tturn:
        ans+=S[chosen][0]
    else:
        ans-=S[chosen][1]
    tturn=not(tturn)
print ans

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    diff_positive = dict()
    diff_negaitive = dict()
    pos_max = 0
    nega_max = 0
    a = [0 for _ in range(n)]
    b = [0 for _ in range(n)]

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

        if ai - bi >= 0:
            diff_positive[i] = ai - bi
            pos_max = max(pos_max, ai - bi)
        else:
            diff_negaitive[i] = bi - ai
            nega_max = max(nega_max, abs(ai - bi))

    posi = sorted(diff_positive.items(), key=lambda x: x[1], reverse=True)
    nega = sorted(diff_negaitive.items(), key=lambda x: x[1], reverse=True)

    if pos_max >= nega_max:
        if len(posi) % 2 == 0:
            taka = posi[::2] + nega[::2]
            aoki = posi[1::2] + nega[1::2]
        else:
            taka = posi[::2] + nega[1::2]
            aoki = posi[1::2] + nega[::2]
    else:
        if len(nega) % 2 == 0:
            taka = posi[::2] + nega[::2]
            aoki = posi[1::2] + nega[1::2]
        else:
            taka = posi[1::2] + nega[::2]
            aoki = posi[::2] + nega[1::2]

    taka_point = 0
    aoki_point = 0

    for t in taka:
        taka_point += a[t[0]]

    for a in aoki:
        aoki_point += b[a[0]]

    print(taka_point - aoki_point)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [None for _ in range(N)]
B = [None for _ in range(N)]
C = [None for _ in range(N)]
D = [None for _ in range(N)]

for i in range(N):
    lst = input().split()
    A[i] = int(lst[0])
    B[i] = int(lst[1])

    C[i] = (A[i], B[i], i)
    D[i] = (B[i], A[i], i)

C.sort(reverse=True)
D.sort(reverse=True)

# すでに取った皿か？
taken = [False for _ in range(N)]

res = 0

i = 0 # Cを先頭から見る
j = 0 # Dを先頭から見る

while i < N and j < N:
    # 高橋
    while i < N:
        x = C[i][2]
        # Cのi番目を見て取られてないなら取る
        if not taken[x]:
            res += A[x]
            taken[x] = True
            break
        # 既に取られているので後を探す
        else: i += 1
    # 青木
    while j < N:
        x = D[j][2]
        if not taken[x]:
            res -= B[x]
            taken[x] = True
            break
        else: j += 1

# 全ての皿を取られてるはず
assert all(taken)

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = []
for i in range(N):
 A, B = map(int, input().split())
 L.append([A - B, A, B])
L.sort()
sumA = 0
sumB = 0
for i in range(N):
  if i % 2 == 0:
    sumA += L[i][1]
  else:
    sumB += L[i][2]
print(sumA - sumB)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [0] * n
for i in range(n):
    a,b = map(int,input().split())
    ab[i] = [a,-b,2 * a-b,2 * b-a]
ans = 0
for i in range(n):
    ab.sort(key=lambda ab:ab[2 + i%2])
    ans += ab[-1][i%2]
    ab.pop()
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input().strip())
arr = []
for n in range(N):
  A, B = list(map(int, input().split()))
  arr.append([ A + B - A , A, B])

arr = sorted(arr, reverse=True)
ta = sum([a[1] for a in arr[::2]])
ao = sum([a[2] for a in arr[1::2]])
print(ta - ao)

Submission status: Wrong Answer

Solution code:
import heapq
from collections import defaultdict

D = defaultdict(int)
N = int(input())
asum = 0
bsum = 0
p = 0

X = []
Y = []
for i in range(N):
	A, B = list(map(int, input().split()))
	X.append([A - B, -A, i])
	Y.append([A - B, -B, i])
X = sorted(X)
Y = sorted(Y)
turn = "a"
a0 = 0
b0 = 0
while p < N:
	if turn == "a":
		while True:
			if D[X[a0][2]] == 0:
				asum -= X[a0][1]
				D[X[a0][2]] += 1
				break
			else:
				a0 += 1

		turn = "b"
	else:
		while True:
			if D[X[b0][2]] == 0:
				bsum -= Y[b0][1]
				D[X[b0][2]] += 1
				break
			else:
				b0 += 1
				
		turn = "a"
	p += 1

print(asum - bsum)

Submission status: Wrong Answer

Solution code:
n = int(input())
tkh = list()
a_b = list()
for i in range(n):
    a,b = input().split()
    a = int(a)
    b= int(b)
    a_b.append([a,b])
    tkh.append([a-b,a,b,i])
aok = tkh.copy()

tkh.sort(key = lambda x : x[2])
tkh.sort(key = lambda x : x[1])
tkh.sort(key = lambda x : x[0])

aok.sort(key = lambda x : x[1])
aok.sort(key = lambda x : x[2])
aok.sort(key = lambda x : x[0])
takahashi, aoki, =0,0

count =0
while count != n:
    if count%2 == 0:
        tmp = tkh.pop()[3]
        if a_b[tmp] != 0:
            takahashi += a_b[tmp][0]
            a_b[tmp] = 0
            count +=1

    else:
        tmp = aok.pop()[3]
        if a_b[tmp] != 0:
            aoki += a_b[tmp][1]
            a_b[tmp] = 0
            count += 1

print(takahashi-aoki)

Submission status: Wrong Answer

Solution code:
import sys
from pprint import pprint
from operator import itemgetter
input = sys.stdin.readline

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

AB.sort(key=itemgetter(0))
AB.reverse()
for i in range(N):
    A[AB[i][2]][1] = i

AB.sort(key=itemgetter(1))
AB.reverse()
for i in range(N):
    B[AB[i][2]][1] = i

ans = 0
for i in range(N):
    if A[i][1] > B[i][1]:
        ans += A[i][0]
    elif A[i][1] < B[i][1]:
        ans -= B[i][0]
    else:
        if A[i][1] % 2 != 0:
            ans += A[i][0]
        else:
            ans -= B[i][0]
print(ans)

Submission status: Wrong Answer

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

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

a=sorted(v,key = lambda x:x[1],reverse = True)

for i in range(N):
    tmp=a.pop(0)
    if i%2==0:
        res += A[i]
    else:
        res -= B[i]

print(res)

Submission status: Wrong Answer

Solution code:

N = int(input().strip())
arr = []
for n in range(N):
  A, B = list(map(int, input().split()))
  arr.append([ A + B - A , A, B])

arr = sorted(arr, reverse=True)
print(arr)
ta = sum([a[1] for a in arr[::2]])
ao = sum([a[2] for a in arr[1::2]])
print(ta - ao)

Submission status: Wrong Answer

Solution code:
n = int(input())
AB = [tuple(map(int,input().split())) + (i,) for i in range(n)]
AB_1 = sorted(AB,reverse=True,key=lambda x:(x[0],x[1]))
AB_2 = sorted(AB,reverse=True,key=lambda x:(x[1],x[0]))

used = set()
i = 0
j = 0
ta = 0
ao = 0
while True:
    while AB_1[i][2] in used:
        i += 1
    ta += AB_1[i][0]
    used.add(AB_1[i][2])
    if len(used) >= n:
        break
    while AB_2[j][2] in used:
        j += 1
    ao += AB_2[j][1]
    used.add(AB_2[j][2])
    if len(used) >= n:
        break
print(ta-ao)

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()

sum = 0
turn = 0

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

print(sum)

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))
a = 0
for i in range(n // 2):
    a += z[2 * i][0] - z[2 * i + 1][1]
if n % 2 == 1:
    a += z[len(z) - 1][0]

print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

AA = collections.deque(numpy.argsort(A)[::-1])
BB = collections.deque(numpy.argsort(B)[::-1])
aans,bans = 0,0
while True:
    try:
        a = AA.popleft()
        aans += A[a]
        if BB[0] == a:
            BB.popleft()
        b = BB.popleft()
        bans += B[b]
        if AA[0] == b:
            AA.popleft()
    except:
        break

if AA:
    aans += A[AA.popleft()]
if BB:
    bans += B[BB.popleft()]

print(aans - bans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
ab=[]
for _ in range(n):
    t,a=map(int,input().split())
    ab.append([t,a,t-a])
sorted_items = sorted(
  ab,
  key = lambda x: x[2],
  reverse=True
)
t=0
a=0
for i in range(n):
    if i%2==0:
        tmp=sorted_items.pop()
        t+=tmp[0]
    else:
        tmp=sorted_items.pop(-1)
        a+=tmp[1]
print(t-a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

a=sorted(v,key = lambda x:x[1])

for i in range(N):
    tmp=a.pop(0)
    if i%2==0:
        res += A[i]
    else:
        res -= B[i]

print(res)

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)

tks = [None for _ in range(N)]
aks = [None for _ in range(N)]
for i in range(N):
    tks[tk[i][1]] = i  # tks[全体のインデックス] = tk内の順位
    aks[ak[i][1]] = i  # aks[全体のインデックス] = ak内の順位

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
N=int(input())
A,B=[],[]
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()
ans=0
inf=float("inf")
eaten=[False]*N
for i in range(N):
  if i%2==0:
    while eaten[A[-1][2]]:
      A.pop()
    while eaten[B[-1][2]]:
      B.pop()
    a1,b0,t=A.pop()
    b1,a2,s=B.pop()
    if t==s:
      ans+=a1
      eaten[t]=True
    else:
      b2=inf    
      while B and b2>10000000000:
        if not eaten[B[-1][2]]:
          b2,a0,g=B.pop()
        else:
          B.pop()
      if a1-b1>=a2-b2:
        ans+=a1
        eaten[t]=True
        B.append((b2,a0,g))
        B.append((b1,a2,s))
      else:
        ans+=a2
        eaten[s]=True
        A.append((a1,b0,t))
        B.append((b2,a0,g))
  else:
    while eaten[A[-1][2]]:
      A.pop()
    while eaten[B[-1][2]]:
      B.pop()
    a1,b2,t=A.pop()
    b1,a0,s=B.pop()
    if t==s:
      ans-=b1
      eaten[t]=True
    else:
      a2=inf    
      while A and a2>10000000000:
        if not eaten[A[-1][2]]:
          a2,b0,g=A.pop()
        else:
          A.pop()
      if b1-a1>=b2-a2:
        ans-=b1
        eaten[s]=True
        A.append((a2,b0,g))
        A.append((a1,b2,t))
      else:
        ans-=b2
        eaten[t]=True
        A.append((a2,b0,g))
        B.append((b1,a0,s))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

# A = list()
# B = list()
# C = list()
# D = list()
A = [None for _ in range(N)]
B = [None for _ in range(N)]
C = [None for _ in range(N)]
D = [None for _ in range(N)]

for i in range(N):
    lst = input().split()
    A[i] = int(lst[0])
    B[i] = int(lst[1])

    C[i] = (A[i], B[i], i)
    D[i] = (B[i], A[i], i)

C.sort(reverse=True)
D.sort(reverse=True)

# すでに取った皿か？
taken = [False for _ in range(N)]

res = 0

i = 0 # Cを先頭から見る
j = 0 # Dを先頭から見る

for _ in range(N):
    # if i >= N or j >= N: break
    # 高橋
    while i < N:
        x = C[i][2]
        # Cのi番目を見て取られてないなら取る
        if not taken[x]:
            res += A[x]
            taken[x] = True
            break
        else: i += 1
    # 青木
    while j < N:
        x = D[j][2]
        if not taken[x]:
            res -= B[x]
            taken[x] = True
            break
        else: j += 1

print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
tkh = list()
a_b = list()
for i in range(n):
    a,b = input().split()
    a = int(a)
    b= int(b)
    a_b.append([a,b])
    tkh.append([a-b,a,b,i])
aok = tkh.copy()

tkh.sort(key = lambda x : x[2])
tkh.sort(key = lambda x : x[1])
tkh.sort(key = lambda x : -x[0])

aok.sort(key = lambda x : x[1])
aok.sort(key = lambda x : x[2])
aok.sort(key = lambda x : -x[0])
takahashi, aoki, =0,0
count =0
while count != n:
    if count%2 == 0:
        tmp = tkh.pop()[3]
        if a_b[tmp] != 0:
            takahashi += a_b[tmp][0]
            a_b[tmp] = 0
            count +=1

    else:
        tmp = aok.pop()[3]
        if a_b[tmp] != 0:
            aoki += a_b[tmp][1]
            a_b[tmp] = 0
            count += 1

print(takahashi-aoki)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [list(map(int,input().split()))+[k] for k in range(N)]

T = sorted(D, key = lambda x: (-x[1],-x[0]))
A = sorted(D, key = lambda x: (-x[0],-x[1]))
U = [1 for k in range(N)]

ans = 0
l = 0
m = 0
for k in range(N):
    if k%2 == 0:
        while U[T[l][2]] == 0:
            l += 1
        ans += T[l][0]
        U[T[l][2]] = 0
    else:
        while U[A[m][2]] == 0:
            m += 1
        ans -= A[m][1]
        U[A[m][2]] = 0

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A, B = [], []
for i in range(n):
    input_a, input_b = map(int, input().split(' '))
    A.append(input_a)
    B.append(input_b)

A, B = sorted(A, reverse=True), sorted(B, reverse=True)

A_point, B_point = 0, 0
for i in range(1, n + 1):

    if i % 2 != 0:  # Aの番
        A_point += A[i - 1]
    else:
        B_point += B[i - 1]
print(A_point - B_point)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

def main(N, A, B, C):
    a, b = 0, 0
    index = list(i[-1] for i in sorted(zip(C, A, range(N)), key=itemgetter(0, 1), reverse=True))
    t = 0
    for _ in range(N):
        i = index.pop()
        if t == 0:
            a += A[i]
        else:
            b += B[i]
        t += 1
        t %= 2
    print(a - b)


if __name__ == "__main__":
    N = int(input())
    A, B = [], []
    C = []
    for _ in range(N):
        a, b = (int(i) for i in input().split())
        A.append(a)
        B.append(b)
        C.append(a+b)
    main(N, A, B, C)

Submission status: Wrong Answer

Solution code:
N = int(input())

# A = list()
# B = list()
# C = list()
# D = list()
A = [None for _ in range(N)]
B = [None for _ in range(N)]
C = [None for _ in range(N)]
D = [None for _ in range(N)]

for i in range(N):
    lst = input().split()
    A[i] = int(lst[0])
    B[i] = int(lst[1])

    C[i] = (A[i], B[i], i)
    D[i] = (B[i], A[i], i)

C.sort(reverse=True)
D.sort(reverse=True)

# すでに取った皿か？
taken = [False for _ in range(N)]

res = 0

i = 0 # Cを先頭から見る
j = 0 # Dを先頭から見る

for i in range(N):
    if i >= N or j >= N: break
    # 高橋
    while i < N:
        x = C[i][2]
        # Cのi番目を見て取られてないなら取る
        if not taken[x]:
            res += A[x]
            taken[x] = True
            break
        else: i += 1
    # 青木
    while j < N:
        x = D[j][2]
        if not taken[x]:
            res -= B[x]
            taken[x] = True
            break
        else: j += 1

print(res)

Submission status: Wrong Answer

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

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

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

ablist.sort(key=itemgetter(0, 1), reverse=True)

tsum = 0
asum = 0

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

# Output
print(tsum - asum)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

for i in range(n):
    a[i].append(a[i][0]-a[i][1])

a_sorted = sorted(a,key = lambda x:(x[0],x[2]),reverse = True)

taka = 0
ao = 0
for i in range(n):
    if i%2 == 0:
        taka += a_sorted[i][0]
    else:
        ao += a_sorted[i][1]

print(int(taka-ao))

Submission status: Wrong Answer

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

counter = 0

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

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
A, B = [], []
for i in range(n):
    input_a, input_b = map(int, input().split(' '))
    A.append(input_a)
    B.append(input_b)

A, B = sorted(A, reverse=True), sorted(B, reverse=True)

A_point, B_point = 0, 0
for i in range(1, n + 1):
    print(i)
    if i % 2 != 0:  # Aの番
        A_point += A[i - 1]
        print("A", A_point, B_point)
    else:
        B_point += B[i - 1]
        print("B", A_point, B_point)
print(A_point - B_point)

Submission status: Wrong Answer

Solution code:
import sys
from pprint import pprint
from operator import itemgetter
input = sys.stdin.readline

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

AB.sort(key=itemgetter(0))
AB.reverse()
for i in range(N):
    A[AB[i][2]][1] = i

AB.sort(key=itemgetter(1))
AB.reverse()
for i in range(N):
    B[AB[i][2]][1] = i

ans = 0
for i in range(N):
    if A[i][1] > B[i][1]:
        ans += A[i][0]
    elif A[i][1] < B[i][1]:
        ans -= B[i][0]
    else:
        if A[i][1] % 2 == 0:
            ans += A[i][0]
        else:
            ans -= B[i][0]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[[i]+list(map(int,input().split())) for i in range(n)]

a=sorted(l,key=lambda x:(-x[1],x[1]-x[2]))
b=sorted(l,key=lambda x:(-x[2],x[1]-x[2]))
pa,pb=0,0
used=set()

v=0
while pa<n and pb<n:
  while pa<n and a[pa][0] in used:
    pa+=1
  if pa<n:
    used.add(a[pa][0])
    v+=a[pa][1]
  while pb<n and b[pb][0] in used:
    pb+=1
  if pb<n:
    used.add(b[pb][0])
    v-=b[pb][2]

print(v)

Submission status: Wrong Answer

Solution code:
a=input()
N=int(a)
T=0
A=0
a_l=list()
b_l=list()
for i in range(N):
    b=input()
    c=b.split()
    a_l.append(int(c[0]))
    b_l.append(int(c[1]))
a_l=sorted(a_l,reverse=True)
b_l=sorted(b_l,reverse=True)
count=0
count2=1
for i in a_l:
    if count%2==0:
        T+=i
        count+=1
    else:
        count+=1
for i in b_l:
    if count2%2==0:
        A+=i
        count2+=1
    else:
        count2+=1
print(T-A)

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 - a
    B[i] = b, a - b
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:
# 2019/01/27
# NIKKEI Programming Contest 2019 - C
from operator import itemgetter

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

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

ablist.sort(key=itemgetter(0, 1), reverse=True)

tsum = 0
asum = 0

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

# Output
print(ablist,tsum,asum)
print(tsum - asum)

Submission status: Wrong Answer

Solution code:
N = int(input())

l= []
for i in range(N):

	a,b = map(int, input().split())
	l.append([a,b,a-b])

l.sort(key=lambda x:(x[2],x[0]))
l.reverse()


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

print(ans)

Submission status: Wrong Answer

Solution code:
base = int(input())

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

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


takahashi = 0
aoki = 0

data.sort()
data.reverse()

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

print(int(takahashi-aoki))

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(abs(a-b))

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

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:
import heapq
from collections import defaultdict

N = int(input())
asum = 0
bsum = 0

X = []
Y = []
for i in range(N):
	A, B = list(map(int, input().split()))
	X.append([A - B, A, B])
X = sorted(X)

turn = "a"
for i in range(N):
	if turn == "a":
		asum += X[i][1]
		turn = "b"
	else:
		bsum += X[i][2]
		turn = "a"

print(asum - bsum)

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()
    D.reverse()

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