Problem:


Score : 400 points

Problem Statement

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

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

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

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

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9

1 \leq B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
:
A_N B_N

Output

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

Sample Input 1

3
10 10
20 20
30 30

Sample Output 1

20

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

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

Sample Input 2

3
20 10
20 20
20 30

Sample Output 2

20

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

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

Sample Input 3

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

Sample Output 3

-2999999997

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



Sample input:
3
10 10
20 20
30 30


Sample output:
20

Submission status: Wrong Answer

Solution code:
def main():
    dishes = int(input())
    takahashi_happiness = []
    aoki_happiness = []
    difference = []
    for i in range(dishes):
        t, a = map(int, input().split())
        takahashi_happiness.append(t)
        aoki_happiness.append(a)
        difference.append((t - a, i))
    difference.sort(key=lambda x: x[0])
    answer = 0
    for i in range(dishes):
        if i % 2 == 0:
            answer += takahashi_happiness[difference[i][1]]
        else:
            answer -= aoki_happiness[difference[i][1]]
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

AB = sorted(AB, key=lambda x:x[2]*(-1))
print(AB)
A = 0
B = 0
for i in range(N):
    if i%2==0:
        A += AB[i][2]
    B += AB[i][1]
        
print(A-B)

Submission status: Wrong Answer

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

AB = sorted(AB,reverse=True)

A = 0
B = 0
for i in range(N):
    if i%2==0:
        A += AB[i][2]
    B += AB[i][1]
        
print(A-B)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N=int(input())
AB=[]

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

AB.sort()
Ta=0
Ao=0

for i in range(N):
    if i%2==0:
        Ta+=AB[i][1]
    else:
        Ao+=AB[i][2]

print(Ta-Ao)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = [None]*n
    b = [None]*n
    f = [True]*n
    for i in range(n):
        x, y = map(int, input().split())
        a[i] = [x, y, i]
        b[i] = [x, y, i]
    a.sort(key=lambda x: (x[1], x[0]), reverse=True)
    b.sort(key=lambda x: (x[0], x[1]), reverse=True)
    cnt = 0
    score = 0
    x, y = 0, 0
    while cnt < n:
        for i in range(x, n):
            if f[a[i][2]]:
                f[a[i][2]] = False
                score += a[i][0]
                x = i
                cnt += 1
                break
        for i in range(y, n):
            if f[b[i][2]]:
                f[b[i][2]] = False
                score -= b[i][1]
                y = i
                cnt += 1
                break
    print(score)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = [None]*n
    b = [None]*n
    f = [True]*n
    for i in range(n):
        x, y = map(int, input().split())
        a[i] = [x, y, i]
        b[i] = [x, y, i]
    a.sort(key=lambda x: (x[0], x[1]), reverse=True)
    b.sort(key=lambda x: (x[1], x[0]), reverse=True)
    cnt = 0
    score = 0
    x, y = 0, 0
    while cnt < n:
        for i in range(x, n):
            if f[a[i][2]]:
                f[a[i][2]] = False
                score += a[i][0]
                x = i
                cnt += 1
                break
        for i in range(y, n):
            if f[b[i][2]]:
                f[b[i][2]] = False
                score -= b[i][1]
                y = i
                cnt += 1
                break
    print(score)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = [None]*n
    b = [None]*n
    f = [True]*n
    for i in range(n):
        x, y = map(int, input().split())
        a[i] = [x, y, i]
        b[i] = [x, y, i]
    a.sort(key=lambda x: (x[0], x[1]), reverse=True)
    b.sort(key=lambda x: (x[1], x[0]), reverse=True)
    cnt = 0
    score = 0
    x, y = 0, 0
    while cnt < n:
        for i in range(x, n):
            if f[a[i][2]]:
                f[a[i][2]] = False
                score += a[i][0]
                x = i
                cnt += 1
                break
        for i in range(y, n):
            if f[b[i][2]]:
                f[b[i][2]] = False
                score -= a[i][1]
                y = i
                cnt += 1
                break
    print(score)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

from collections import deque

Adif=sorted(Adif, key=lambda x: x[1])
Adif=deque(Adif)
choku=0
aoki=0
for i in range(n):
    if i%2==0:
        x=Adif.popleft()
        choku+=x[0]
    else:
        x=Adif.popleft()
        aoki+=x[0]-x[1]
print(choku-aoki)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
AB = [LIST() for _ in range(N)]

X = -sum([x[1] for x in AB])

for i, (A, B) in enumerate(sorted(AB, key=lambda x:x[0]+x[1])):
	if i%2 == 0:
		X += A+B
print(X)

Submission status: Wrong Answer

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

def main():
    N = int(input())
    tf,af = [],[]
    for i in range(N):
        a,b = map(int,input().split())
        tf.append((-a,a-b,i))
        af.append((-b,b-a,i))
    
    tf.sort(key=itemgetter(0,1))
    af.sort(key=itemgetter(0,1))

    use = [False for i in range(N)]
    tpoint,apoint,tnow,anow = 0,0,0,0
    while not all(use):
        while use[tf[tnow][2]]:
            tnow += 1
        tpoint -= tf[tnow][0]
        use[tf[tnow][2]] = True
        if all(use):
            break
        while use[af[anow][2]]:
            anow += 1
        apoint -= af[anow][0]
        use[af[anow][2]] = True
    
    print(tpoint-apoint)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[0]*n
t=0
for i in range(n):
  a,b=map(int,input().split())
  s[i]=a+b
  t+=b
s.sort()
s=s[::-1]
print(sum(s[:n//2+(n%2==1)])-t)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
N = int(input())
AB = []
for i in range(N):
    a, b = [int(i) for i in input().split()]
    AB.append((a, b, i))
AB2 = deepcopy(AB)
f = [0]*N
ans = 0

AB.sort(key=lambda x: x[1])
AB.sort(key=lambda x: x[0])
AB2.sort(key=lambda x: x[0])
AB2.sort(key=lambda x: x[1])

abIdx, ab2Idx = 0, 0
for i in range(N-1, -1, -1):
    if i % 2:
        while f[AB2[ab2Idx][2]]:
            ab2Idx += 1
        ans -= AB2[ab2Idx][1]
        f[AB2[ab2Idx][2]] |= 1
        ab2Idx += 1
    else:
        while f[AB[abIdx][2]]:
            abIdx += 1
        ans += AB[abIdx][0]
        f[AB[abIdx][2]] |= 1
        abIdx += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N)]
ans = 0

AB.sort(key=lambda x: min(x), reverse=True)
AB.sort(key=lambda x: max(x), reverse=True)
for i, ab in enumerate(AB):
    if i % 2:
        ans -= ab[1]
    else:
        ans += ab[0]

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
ab=[tuple(map(int,input().split())) for _ in range(n)]
d=[ab[i][1]+ab[i][0] for i in range(n)]
d.sort()
k=(n-1)//2+1
ans=0
for i in range(n):
  ans-=ab[i][1]
for i in range(1,k+1):
  ans+=d[-i]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
ab=[tuple(map(int,input().split())) for _ in range(n)]
d=[ab[i][1]+ab[i][0] for i in range(n)]
d.sort()
k=(n-1)//2+1
ans=0
for i in range(n):
  ans-=ab[i][1]
for i in range(k):
  ans+=d[-i]
print(ans)

Submission status: Wrong Answer

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

AB.sort(reverse=True, key=lambda x:(x[0],x[1]) if x[0]>x[1] else (x[1],x[0]))
t = sum(AB[i][0] for i in range(0, N, 2))
a = sum(AB[i][1] for i in range(1, N, 2))

print(t-a)

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = sorted([list(map(int,input().split())) for i in range(N)],key = lambda x:x[0]-x[1])
Tsum = sum(AB[i][0] for i in range(N) if i%2 == 0)
Asum = sum(AB[i][1] for i in range(N) if i%2 == 1)
print(Tsum-Asum)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    ls = [[int(x) for x in input().split()] for _ in range(N)]
    for i in range(N):
        ls[i].append(ls[i][0]-ls[i][1])
    ls = sorted(ls,key=lambda x:(x[2],-x[0]))
    ans = [0,0]

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

    print(ans[0]-ans[1])
        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

A.sort(key=lambda k: k[1], reverse=True)
B.sort(key=lambda k: k[1], reverse=True)
used = [False]*N

takahashi, aoki = 0, 0
A_idx, B_idx = 0, 0

for i in range(N):
    if i%2==0:
        while True:
            if not used[A[A_idx][0]]:
                takahashi += A[A_idx][1]
                used[A[A_idx][0]] = True
                break
            else:
                A_idx += 1
    else:
        while True:
            if not used[[B_idx][0]]:
                aoki += B[B_idx][1]
                used[B[B_idx][0]] = True
                break
            else:
                B_idx += 1
                
print(takahashi-aoki)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[0]*N
B=[0]*N
diff=[0]*N
for i in range(N):
  A[i],B[i]=map(int,input().split())
  diff[i]=[A[i]+B[i],i]
  
diff=sorted(diff,key=lambda x:x[1])[::-1]

taka=0
aoki=0
for i in range(len(diff)):
  if i%2==0:
    taka+=A[diff[i][1]]
  else:
    aoki+=B[diff[i][1]]

print(taka-aoki)

Submission status: Wrong Answer

Solution code:
# どうせ何を喰っても自分のポイントは入るので、
# 高橋くんは青木くんの得られるポイントの最大のやつを,青木くんは高橋くんのvice versa
n = int(input())
arr = []
used = [False for _ in range(n)]
for i in range(n):
    a, b = map(int, input().split())
    arr.append([i, a, b])

tak = sorted(arr, key=lambda x: x[1], reverse=True)
aok = sorted(arr, key=lambda x: x[2], reverse=True)
takp, aokp = 0, 0
# 毎回どのインデックスを使ってないかを調べるとTLEなるので、
# どうせソート済みを利用してインデックス参照して次に喰う料理のインデックスを探す
c = 0
taki, aoki = (0, 0)
while c < n:
    if c % 2 == 0:
        # 高橋くんのターン
        while used[aoki]:
            aoki += 1
        used[aoki] = True
        takp += aok[aoki][1]  # 青木くんの得られるポイントで降順ソートしたインデックスの料理を食べた時に得られる高橋くんのポイント
    else:
        # 青木くんのターン
        while used[taki]:
            taki += 1
        used[taki] = True
        aokp += tak[taki][2]  # 略
    c += 1

print(takp - aokp)

Submission status: Wrong Answer

Solution code:
import heapq

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

flags = [1 for _ in range(N)]
Asum, Bsum = 0, 0
ans = 0
for i in range(N):
  if i%2==0:
    while len(A)>0:
      neg_a, _, ii = heapq.heappop(A)
      if flags[ii] == 1:
        flags[ii] = 0
        break
    Asum += -neg_a
  else:
    while len(B)>0:
      neg_b, _, ii = heapq.heappop(B)
      if flags[ii] == 1:
        flags[ii] = 0
        break
    Bsum += -neg_b  
print(Asum-Bsum)

Submission status: Wrong Answer

Solution code:
import heapq

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

flags = [1 for _ in range(N)]
Asum, Bsum = 0, 0
ans = 0
for i in range(N):
  if i%2==0:
    flag = 0
    while flag == 0:
      neg_a, _, ii = heapq.heappop(A)
      flag = flags[ii]
      flags[ii] = 0
    Asum += -neg_a
  else:
    flag = 0
    while flag == 0:
      neg_b, _, ii = heapq.heappop(B)
      flag = flags[ii]
      flags[ii] = 0
    Bsum += -neg_b  
print(Asum-Bsum)

Submission status: Wrong Answer

Solution code:
import heapq

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

flags = [1 for _ in range(N)]
Asum, Bsum = 0, 0
ans = 0
for i in range(N):
  if i%2==0:
    flag = 0
    while flag == 0:
      neg_a, ii = heapq.heappop(A)
      flag = flags[ii]
      flags[ii] = 0
    Asum += -neg_a
  else:
    flag = 0
    while flag == 0:
      neg_b, ii = heapq.heappop(B)
      flag = flags[ii]
      flags[ii] = 0
    Bsum += -neg_b  
print(Asum-Bsum)

Submission status: Wrong Answer

Solution code:
print("解説確認")

Submission status: Wrong Answer

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

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))
l.sort(reverse=True,key=lambda x:(x[0]-x[1],x[0]))
ans=0
for i,e in enumerate(l):
    if i%2==0:
        ans+=e[0]
    elif i%2==1:
        ans+=-e[1]
print(ans)

Submission status: Wrong Answer

Solution code:
def examC():
    N = I()
    A = [0]*N; B = [0]*N
    for i in range(N):
        A[i], B[i] = LI()
    taka = 0; aoki = 0
    value = [[i] for i in range(N)]
    for i in range(N):
        cur = A[i]+B[i]
        value[i].append(cur)
    value.sort(key=lambda x:x[1])
    for i in range(N):
        if i%2==0:
            taka += A[value[i][0]]
        else:
            aoki += B[value[i][0]]
    ans = taka-aoki
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()

Submission status: Wrong Answer

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
A, B = list(zip(*[map(int, sys.stdin.buffer.readline().split()) for _ in range(N)]))

A = np.array(A, dtype=int)
B = np.array(B, dtype=int)

order = np.maximum(A, B).argsort()[::-1]
l = 0
r = N - 1
# a = 0
# b = 0
# while True:
#     if l >= r:
#         break
#     a += A[l]
#     l += 1
#     if l >= r:
#         break
#     b += B[r]
#     r -= 1

a  = A[order[::2]].sum()
b  = B[order[1::2]].sum()
print(a - b)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]
A = sorted(A,key=lambda x:x[0])
for i in range(N):
    A[i].append(i)
B = copy.deepcopy(A)
B = sorted(B,key=lambda x:x[1])
for i in range(N):
    A[B[i][2]][2] = i
hist = [0 for _ in range(N)]
curA = N-1
curB = N-1
cnt = 0
turn = 1
while curA>-1 and curB>-1:
    x = A[curA]
    y = B[curB]
    if turn:
        if x[0]==y[0]:
            cnt += x[0]
            hist[curA] = 1
            curA -= 1
            while curA>-1:
                if hist[curA]==0:break
                curA -= 1
            curB -= 1
            while curB>-1:
                if hist[B[curB][2]]==0:break
                curB -= 1
        elif x[0]-y[1]>=y[0]-x[1]:
            cnt += x[0]
            hist[curA] = 1
            curA -= 1
            while curA>-1:
                if hist[curA]==0:
                    break
                curA -= 1
        else:
            cnt += y[0]
            hist[B[curB][2]] = 1
            curB -= 1
            while curB>-1:
                if hist[B[curB][2]]==0:
                    break
                curB -= 1
    else:
        if x[1]==y[1]:
            cnt -= y[1]
            hist[curA] = 1
            curA -= 1
            while curA>-1:
                if hist[curA]==0:break
                curA -= 1
            curB -= 1
            while curB>-1:
                if hist[B[curB][2]]==0:break
                curB -= 1
        elif y[1]-x[0]>=x[1]-y[0]:
            cnt -= y[1]
            hist[B[curB][2]] = 1
            curB -= 1
            while curB>-1:
                if hist[B[curB][2]]==0:
                    break
                curB -= 1
        else:
            cnt -= x[1]
            hist[curA] = 1
            curA -= 1
            while curA>-1:
                if hist[curA]==0:
                    break
                curA -= 1
    turn = (turn+1)%2
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
import sys
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
    
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n=inp()
    ab=[]
    for _ in range(n):
        x,y=inpm()
        ab.append((x+y,x,y))
    ab.sort()
    pa=0
    pb=0
    for i in range(n):
        if i%2 == 0:
            pa+=ab[i][1]
        else:
            pb+=ab[i][2]
    print(pa-pb)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces
sys.setrecursionlimit(10 ** 7)

N = ri()
A = []
B = []

for i in range(N):
    a, b = rl()
    A.append(a)
    B.append(b)

A = np.array(A)
B = np.array(B)
diff = A - B
D = []
for i, x in enumerate(diff):
    D.append((x, i))

D.sort(reverse=True)
A = list(A)
B = list(B)
ta = 0
ao = 0
for x, i in D[::2]:
    ta += A[i]
for x, i in D[1::2]:
    ao += B[i]

print(ta-ao)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces
sys.setrecursionlimit(10 ** 7)

N = ri()
A = []
B = []

for i in range(N):
    a, b = rl()
    A.append(a)
    B.append(b)

A = np.array(A)
B = np.array(B)
diff = A - B
D = []
for i, x in enumerate(diff):
    D.append((x, i))

D.sort()
A = list(A)
B = list(B)
ta = 0
ao = 0
for x, i in D[::2]:
    ta += A[i]
for x, i in D[1::2]:
    ao -= B[i]

print(ta-ao)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces
sys.setrecursionlimit(10 ** 7)

N = ri()
A = []
B = []

for i in range(N):
    a, b = rl()
    A.append(a)
    B.append(b)

A = np.array(A)
B = np.array(B)
diff = A - B
D = []
for i, x in enumerate(diff):
    D.append((x, i))

D.sort()
A = list(A)
B = list(B)
ta = 0
ao = 0
for x, i in D[::2]:
    ta += A[i]
for x, i in D[1::2]:
    ao += B[i]

print(ta-ao)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=[]
a=[]
b=[]
for i in range(n):
	x,y=map(int,input().split())
	a.append(x)
	b.append(y)
	c.append([x-y,i])
c.sort()
c.reverse()
q=[]
qq=[]
for i in range(n):
	if i%2==0:
		q.append(c[i][1])
	else:
		qq.append(c[i][1])
ans=0
for i in range(len(q)):
	ans+=a[q[i]]
for i in range(len(qq)):
	ans-=b[qq[i]]
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#"""
#Created on Wed Nov 20 17:37:14 2019
#
#@author: manakamura
#"""

#https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_c

n= int(input())
#s= input()
tup = []
for i in range(0,n):
    tmp = input().split()
    tmpa,tmpb = list(map(lambda a: int(a), tmp))
    tup.append([abs(tmpa-tmpb),tmpa,tmpb])

#print(tup)
tup=sorted(tup, reverse=True, key=lambda x:x[0])
#print(tup)

total=0
for i in range(0,n):
    if (i%2==0):
       total+=tup[i][1]
    else:
       total-=tup[i][2]
          
print(total)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#"""
#Created on Wed Nov 20 17:37:14 2019
#
#@author: manakamura
#"""

#https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_c

n= int(input())
#s= input()
tup = []
for i in range(0,n):
    tmp = input().split()
    tmpa,tmpb = list(map(lambda a: int(a), tmp))
    tup.append([tmpa-tmpb,tmpa,tmpb])



#print(tup)
tup=sorted(tup, reverse=True, key=lambda x:x[0])
#print(tup)

total=0
for i in range(0,n):
    if (i%2==0):
       total+=tup[i][1]
    else:
       total-=tup[i][2]
          
print(total)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
ab = [0] * n
for i in range(n):
    a,b = inpl()
    ab[i] = (abs(a-b),a,b)
ab.sort(reverse=True)
# print(ab)
x = 0
y = 0
for i,j in enumerate(ab):
    if i%2:
        y += j[2]
    else:
        x += j[1]
print(x-y)

Submission status: Wrong Answer

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

#input
N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

#output
C = [(a, b) for a, b in zip(A, B)]
C = sorted(C, key = lambda x:(x[0], x[1]), reverse = True)
D = [0] * N
E = [0] * N
for i in range(N):
    D[i] = C[i][0]
    E[i] = C[i][1]

answer = sum(D[0::2]) - sum(E[1::2])

print(answer)

Submission status: Wrong Answer

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

#input
N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

#output
C = [(a, b) for a, b in zip(A, B)]
sorted(C, key = lambda x:(x[0], x[1]), reverse = True)
D = [0] * N
E = [0] * N
for i in range(N):
    D[i] = C[i][0]
    E[i] = C[i][1]

answer = sum(D[0::2]) - sum(E[1::2])

print(answer)

Submission status: Wrong Answer

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

#input
N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

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

answer = sum(A[0::2]) - sum(B[1::2])

print(answer)

Submission status: Wrong Answer

Solution code:
import heapq
n = int(input())
a = [[int(i) for i in input().split()] for _ in range(n)]

taka = []
ao = []
for idx, val in enumerate(a):
    heapq.heappush(taka, (-(val[1]-val[0]),idx))
    heapq.heappush(ao, (-val[1]+val[0],idx))

takas = 0
aos = 0
curn = 0
done = set()
while curn < n:
    if curn%2 == 0:
        while len(taka) >= 1:
            cur = heapq.heappop(taka)
            if cur[1] not in done:
                takas += a[cur[1]][0]
                done.add(cur[1])
                curn += 1
                break
    else:
        while len(ao) >= 1:
            cur = heapq.heappop(ao)
            if cur[1] not in done:
                # print(cur)
                aos += a[cur[1]][1]
                done.add(cur[1])
                curn += 1
                break
print(takas-aos)

Submission status: Wrong Answer

Solution code:
#c
n=int( input())
a=[0]*n
b=[0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split() )
    
d=[[a[i],b[i],a[i]+b[i]] for i in range(n)]
d.sort(reverse=True,key=lambda x:x[2])
tsum = sum( d[i][0] for i in range((n+1)//2)  ) 
asum = sum( d[i][1] for i in range((n+1)//2,n))
print(tsum-asum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import heapq
N=int(input())
ab=[list(map(int,input().split())) for _ in range(N)]
sab=[[-ab[i][0]-ab[i][1],i] for i in range(N)]
heapq.heapify(sab)

ans=0
for i in range(N):
  if i%2==0:
    ind=heapq.heappop(sab)[1]
    ans+=ab[i][0]
  else:
    ind=heapq.heappop(sab)[1]
    ans-=ab[i][1]
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
read = sys.stdin.read

N, *AB = map(int, read().split())
A = AB[::2]
B = AB[1::2]
ab = [a + b for a, b in zip(A, B)]
ab, A, B = zip(*sorted(zip(ab, A, B), key=itemgetter(0)))
print(sum(A[::2]) - sum(B[1::2]))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read

N, *AB = map(int, read().split())
A = AB[::2]
B = AB[1::2]
ab = [a + b for a, b in zip(A, B)]
ab, A, B = zip(*sorted(zip(ab, A, B)))
print(sum(A[::2]) - sum(B[1::2]))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
ab=[tuple(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1])
ab.sort(key=lambda x:x[0], reverse=True)
ta=0
ao=0
for i in range(n):
    if i%2==0:
        ta+=ab[i][0]
    else:
        ao+=ab[i][1]

print(ta-ao)

Submission status: Wrong Answer

Solution code:
import collections
all_plate = {}

n = int(input())
for i in range(n):
    a, b = [ int(v) for v in input().split() ]
    c = a-b
    if c in all_plate:
        all_plate[c].append([a,b])
    else:
        all_plate[c] = [[a,b]]

for i in all_plate:
    all_plate[i].sort(reverse = True)
all_plate = sorted(all_plate.items())
all_plate_2 = []
for i in all_plate:
    all_plate_2 += i[1]
all_plate_2 = collections.deque(all_plate_2)

tak, aok = 0, 0
for i in range(n):
    if i == n - 1:
        a, b = all_plate_2.pop()
        if i % 2 == 0:
            tak += a
        else:
            aok += b
    else:
        a, b = all_plate_2.popleft()
        c, d = all_plate_2.pop()
        if a-b >= d-c:
            all_plate_2.append((c,d))
            if i % 2 == 0:
                tak += a
            else:
                aok += b
        else:
            all_plate_2.appendleft((a,b))
            if i % 2 == 0:
                tak += c
            else:
                aok += d

print(tak-aok)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
X = []
N = int(input())
dic = {}
for i in range(N):
  a, b = map(int, input().split())
  heappush(X,(a+b,a,b))
count = 0
T = 0
A = 0
while X:
  m, a, b = heappop(X)
  if count%2==0:
    T += a
  else:
    A += b
  count += 1

print(T-A)

Submission status: Wrong Answer

Solution code:
# 2019/10/24

from collections import deque

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

ab=deque(sorted(ab,key=lambda x:x[2],reverse=True))
A=0
B=0
turn=1
for i in range(n-1):
    p=ab.popleft()
    if turn:A+=p[0]
    else:B+=p[1]
    turn=1-turn

ax=0
bx=0
for i in range(len(ab)):
    a,b,_=ab[i]
    ax=max(ax,a)
    bx=max(bx,b)

if turn:A+=ax
else:B+=bx

print(A-B)

Submission status: Wrong Answer

Solution code:
n,*L=map(int,open(0).read().split())
s=sorted([(a,-b)for a,b in zip(*[iter(L)]*2)],key=lambda x:sum(x))[::-1]
print(sum(s[i][i%2]for i in range(n)))

Submission status: Wrong Answer

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