Problem:


Score : 400 points

Problem Statement

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

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

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

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

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9

1 \leq B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
:
A_N B_N

Output

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

Sample Input 1

3
10 10
20 20
30 30

Sample Output 1

20

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

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

Sample Input 2

3
20 10
20 20
20 30

Sample Output 2

20

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

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

Sample Input 3

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

Sample Output 3

-2999999997

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



Sample input:
3
10 10
20 20
30 30


Sample output:
20

Submission status: Wrong Answer

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

A1 = 0
A2 = 0

for i in range(N):
    if len(L) == 0:
        break
    L.sort(reverse=True,key=lambda x: x[0])
    A1 = A1 + L.pop(0)[0]

    if len(L) == 0:
        break
    L.sort(reverse=True,key=lambda x: x[1])
    A2 = A2 + L.pop(0)[1]

print(A1-A2)

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


takahashi = sorted(ab, key=lambda x:(-x[1], -x[2]))
aoki = sorted(ab, key=lambda x:(-x[2], -x[1]))
check = [False for _ in range(N)]

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

        while check[a[0]]:
            j += 1
            a = aoki[j]

        if t[1] >= a[2]:
            ans += t[1]
            check[t[0]] = True
            i += 1
        else:
            ans += a[1]
            check[a[0]] = True
            j += 1
    else:
        t = takahashi[i]
        a = aoki[j]
        while check[t[0]]:
            i += 1
            t = takahashi[i]

        while check[a[0]]:
            j += 1
            a = aoki[j]

        if t[1] >= a[2]:
            ans -= t[2]
            check[t[0]] = True
            i += 1
        else:
            ans -= a[2]
            check[a[0]] = True
            j += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array([0 for i in range(N)], np.int64)
B = np.array([0 for i in range(N)], np.int64)
TA = 0
AO = 0
for i in range(N):
    A[i], B[i] = map(int, input().split())
AmB = np.array([A[i] + B[i] for i in range(N)])
index = np.argsort(AmB)
print(np.sum(A[index[::2]]) - np.sum(B[index[1::2]]))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A, B = [], []

gain = []

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

    gain.append((a, i, 0))
    gain.append((b, i, 1))

gain = sorted(gain, reverse=True)

used = set()
ans = 0
cnt = 0
# print(gain)
for v, i, p in sorted(gain, reverse=True):
    if i in used:
        continue
    used.add(i)

    if cnt % 2 == 0:
        ans += A[i]
    else:
        ans -= B[i]

    cnt = (cnt + 1) % 2


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])
        B.append([b, a, a + b])

    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)
        if a < N:
            if check[a] == 1 and a < N:
                a += 1
        if t < N:
            if check[t] == 1 and t < N:
                t += 1

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

        if a < N:
            if check[a] == 1 and a < N:
                a += 1
        if t < N:
            if check[t] == 1 and t < N:
                t += 1

        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] = 1
                a += 1
            else:
                Aoki += B[t][0]
                check[t] = 1
                t += 1
        else:
            if a < N:
                Aoki += A[a][1]
                check[a] += 1
            elif t < N:
                Aoki += B[t][0]
                check[t] = 1
                t += 1


    print(Takahashi - Aoki)

C()

Submission status: Wrong Answer

Solution code:
import sys
fin = sys.stdin.readline
from functools import lru_cache

N = int(fin())
happinesses = [tuple(int(elem) for elem in fin().split()) for _ in range(N)]
indices_happi_takahashi = sorted(range(N), key=lambda i: happinesses[i], reverse=True)
indices_happi_aoki = sorted(range(N), key=lambda i: happinesses[i][::-1], reverse=True)
used = [False] * N

takahashi_score = 0
cur_idx_takahashi = 0
cur_idx_aoki = 0
for i in range(N):
    while used[indices_happi_takahashi[cur_idx_takahashi]] == True:
        cur_idx_takahashi += 1
    while used[indices_happi_aoki[cur_idx_aoki]] == True:
        cur_idx_aoki += 1
    idx_takamax = indices_happi_aoki[cur_idx_takahashi]
    idx_aokimax = indices_happi_aoki[cur_idx_aoki]
    if i % 2 == 0:
        score_when_takamax = happinesses[idx_takamax][0] - happinesses[idx_aokimax][1]
        score_when_aokimax = happinesses[idx_aokimax][0] - happinesses[idx_takamax][1]
        if score_when_takamax >= score_when_aokimax:
            takahashi_score += happinesses[idx_takamax][0]
            used[idx_takamax] = True
        else:
            takahashi_score += happinesses[idx_aokimax][1]
            used[idx_aokimax] = True
    else:
        score_when_takamax = happinesses[idx_takamax][1] - happinesses[idx_aokimax][0]
        score_when_aokimax = happinesses[idx_aokimax][1] - happinesses[idx_takamax][0]
        if score_when_takamax >= score_when_aokimax:
            takahashi_score -= happinesses[idx_takamax][1]
            used[idx_takamax] = True
        else:
            takahashi_score -= happinesses[idx_aokimax][1]
            used[idx_aokimax] = True
print(takahashi_score)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

print(sol)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
AB = np.zeros((3, N))

for i in range(N):
    tmpA, tmpB = map(int, input().split())
    AB[0, i] = tmpA + tmpB
    AB[1, i] = tmpA
    AB[2, i] = tmpB

AB = AB[:, np.argsort(AB[0, :])]

point = 0
for i in range(N):
    if i%2==0:
        point += AB[1, i]
    else:
        point -= AB[2, i]
print(int(point))

Submission status: Wrong Answer

Solution code:
N = input()

data = []

for i in range(N):
    A,B = map(int,raw_input().split())
    C = A-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:
import sys
fin = sys.stdin.readline
from functools import lru_cache

N = int(fin())
happinesses = [tuple(int(elem) for elem in fin().split()) for _ in range(N)]
indices_happi_takahashi = sorted(range(N), key=lambda i: happinesses[i], reverse=True)
indices_happi_aoki = sorted(range(N), key=lambda i: happinesses[i][::-1], reverse=True)
used = [False] * N

takahashi_score = 0
cur_idx_takahashi = 0
cur_idx_aoki = 0
for i in range(N):
    while used[indices_happi_takahashi[cur_idx_takahashi]] == True:
        cur_idx_takahashi += 1
    while used[indices_happi_aoki[cur_idx_aoki]] == True:
        cur_idx_aoki += 1
    idx_takamax = indices_happi_aoki[cur_idx_takahashi]
    idx_aokimax = indices_happi_aoki[cur_idx_aoki]
    if i % 2 == 0:
        score_when_takamax = happinesses[idx_takamax][0] - happinesses[idx_aokimax][1]
        score_when_aokimax = happinesses[idx_aokimax][0] - happinesses[idx_takamax][1]
        if score_when_takamax >= score_when_aokimax:
            takahashi_score += happinesses[idx_takamax][0]
            used[idx_takamax] = True
        else:
            takahashi_score += happinesses[idx_aokimax][1]
            used[idx_aokimax] = True
    else:
        score_when_takamax = happinesses[idx_takamax][1] - happinesses[idx_aokimax][0]
        score_when_aokimax = happinesses[idx_aokimax][1] - happinesses[idx_takamax][0]
        if score_when_takamax >= score_when_aokimax:
            takahashi_score -= happinesses[idx_takamax][1]
            used[idx_takamax] = True
        else:
            takahashi_score -= happinesses[idx_aokimax][1]
            used[idx_aokimax] = True

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = []
for _ in range(N):
    A, B = list(map(int, input().split()))
    arr.append([A, B, A-B])
arr = sorted(arr, key=lambda x: x[0])
arr = sorted(arr, key=lambda x: x[2])

a = 0
b = 0
for i in range(N):
    if i % 2 == 0:
        a += arr[i][0]
    else:
        b += arr[i][1]
print(a-b)

Submission status: Wrong Answer

Solution code:
n=int(input())
happiness=[list(map(int,input().split())) for i in range(n)]
a=0
b=0
li = [x for x in zip(*happiness)]
for i in range(n):
  if li[0][i] >= li[1][i]:
    a+=li[0][i]
  else:
    b+=li[1][i]
ans=a-b
print(str(ans))

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

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


diff = [[ryouri[i][0] - ryouri[i][1], i] for i in range(n)]
diff = sorted(diff, key=lambda x: x[0])

score_t = 0
score_k = 0

for i in range(n):
    if i % 2 == 0:
        score_t += ryouri[diff[int(math.floor(i/2))][1]][0]
    else:
        score_k += ryouri[diff[::-1][int(math.floor(i/2))][1]][1]
        
print(score_t - score_k)

Submission status: Wrong Answer

Solution code:
# C
import numpy as np
N = int(input())
a_list, b_list = [], []
diff_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
    diff_list.append(a-b)
a_list = np.asarray(a_list)
b_list = np.asarray(b_list)
diff_list = np.asarray(diff_list)
    
aoki = []
taka = []
def aoki_act(current_b, diff):
    if len(list(set(diff))) == 1:
        idx = np.argmax(current_b)
    else:
        idx = np.argmax(-diff)
    return idx
def taka_act(current_a, diff):
    if len(list(set(diff))) == 1:
        idx = np.argmax(current_a)
    else:
        idx = np.argmax(diff)
    return idx

while(len(a_list) > 0):
#     print(a_list, b_list)
    taka_idx = taka_act(a_list, diff_list)
    taka.append(a_list[taka_idx])
    a_list = np.delete(a_list, taka_idx)
    b_list = np.delete(b_list, taka_idx)
    diff_list = np.delete(diff_list, taka_idx)
#     print(a_list, b_list)

    if len(a_list) == 0:
        break
    
    aoki_idx = aoki_act(b_list, diff_list)
    aoki.append(b_list[aoki_idx])
    a_list = np.delete(a_list, aoki_idx)
    b_list = np.delete(b_list, aoki_idx)
    diff_list = np.delete(diff_list, aoki_idx)
#     print(a_list, b_list)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
taka = sorted(ab, key=lambda x:(x[1], x[0]))[::-1]
res = 0
for i in range(n):
    if i % 2 == 0: # takahashi
        res += taka[i][0]
    else: #aoki
        res -= taka[i][1]
print(res)

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

rec1 = sorted(rec, key=lambda x: (x[0] - x[1], -x[0]))
used = [-1] * N
i = 0
j = 0
k = 0
num = 0
while k < N:
    if k % 2 == 0:
        num += rec1[i][0]
        i += 1
    else:
        num -= rec1[i][1]
        i += 1

    k += 1

print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
dif=[]

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

dif.sort()
dif.reverse()
tak = 0
aok = 0
for i in range(N):
    if i % 2 == 0:
        tak += A[i]
    else:
        aok += B[i]

print(tak - aok)

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

t = 0
for ab in AB[0::2]:
    t += ab[1]

a = 0
for ab in AB[1::2]:
    a += ab[2]
    
print(t - a)

Submission status: Wrong Answer

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

table = [[0] * 4 for i in range(N)]
for i, (Ai, Bi) in enumerate(AB):
    table[i][0] = Ai
    table[i][1] = Bi 
    table[i][2] = Ai - Bi
    table[i][3] = i

table_A = list(table)
table_A.sort(key=lambda x: x[2])
table_A.sort(key=lambda x: -x[0])

table_B = list(table)
table_B.sort(key=lambda x: -x[2])
table_B.sort(key=lambda x: -x[1])

ans = 0
idx_a = 0
idx_b = 0
state = [0] * N
for i in range(N):
    # print("#", ans, idx_a, idx_b)
    if i % 2:
        while True:
            A_tmp, B_tmp, score_tmp, i_tmp = table_B[idx_b]
            if state[i_tmp] < 1:
                # print("## b", B_tmp)
                ans -= B_tmp # inverted
                state[i_tmp] = 1
                idx_b += 1
                break
            idx_b += 1
    else:
        while True:
            A_tmp, B_tmp, score_tmp, i_tmp = table_A[idx_a]
            if state[i_tmp] < 1:
                # print("## a", A_tmp)
                ans += A_tmp
                state[i_tmp] = 1
                idx_a += 1
                break
            idx_a += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
m = [[0] * 3 for i in range(n)]

for i in range(n):
    a, b = map(int, input().split())
    m[i][0] = a - b
    m[i][1] = a
    m[i][2] = b

if n == 1:
    print(m[0])
    exit()

m.sort()
m = sorted(m, key=lambda x:(x[0],-x[1],x[2]))

takahashi = 0
aoki = 0
for i in range(0, n):
    if i % 2 == 0:
        takahashi += m[i][1]
    else:
        aoki += m[i][2]

ans = takahashi - aoki
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = [list(map(int,input().split())) for i in range(N)]
lst.sort(key=lambda x:(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())
f=[0]*n
d=[list(map(int,input().split()))+[i]for i in range(n)]
t=sorted(d,key=lambda x:(x[0],x[1]))
a=sorted(d,key=lambda x:(x[1],x[0]))
sumt=suma=0
while t:
    x=t.pop()
    while t and f[x[2]]:
        x=t.pop()
    if not f[x[2]]:
        sumt+=x[0]
    f[x[2]]=1
    if a:
        y=a.pop()
        while a and f[y[2]]:
            y=a.pop()
        if not f[y[2]]:
            suma+=y[1]
        f[y[2]]=1
print(sumt-suma)

Submission status: Wrong Answer

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

T = []
A = []
eaten = [False]*N

happiness1 = sorted(happiness, key=lambda x:(x[3], x[0], x[1]))
happiness2 = sorted(happiness, key=lambda x:(x[4], x[1], x[0]))

for i in range(N):
    if i % 2 == 0: # Takahashi
        while True:
            a, _, _, _, idx = happiness1.pop()
            if not eaten[idx]:
                eaten[idx] = True
                T.append(a)
                break
    else: # Aoki
        while True:
            _, b, _, _, idx = happiness2.pop()
            if not eaten[idx]:
                eaten[idx] = True
                A.append(b)
                break

print(sum(T) - sum(A))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N = int(input())
dish = [[0 for _ in range(3)] for _ in range(N)]
Takahashi = []
Aoki = []
for i in range(N):
    dish[i][0],dish[i][1] = [int(x) for x in input().split()]
    dish[i][2] = dish[i][0]+dish[i][1]
dish.sort(key=itemgetter(2),reverse=True)
for i in range(int(N/2)):
    Takahashi.append(dish[2*i][0])
    if(2*i<=N-2):
        Aoki.append(dish[2*i+1][1])
print(sum(Takahashi)-sum(Aoki))

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[2]))
b=sorted(l,key=lambda x:(-x[2],-x[1]))
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:
n=int(input())
A=[]
for i in range(n):
    A.append(list(map(int,input().split())))

A.sort(reverse=1)

B=[]
for i in range(n):
    B.append([i,A[i][0],A[i][1]-A[i][0]])
    
B.sort(reverse=1,key=lambda x:x[2])
B.sort(reverse=1,key=lambda x:x[1])

#print(B)

C=[]
for i in range(n):
    C.append([i,A[i][1],A[i][0]-A[i][1]])
    
C.sort(reverse=1,key=lambda x:x[2])
C.sort(reverse=1,key=lambda x:x[1])


#print(B)
#print(C)

check=[0 for i in range(n)]
S=[0,0]
s0=0
s1=0
for i in range(n):
    if i%2==0 :
        while check[B[s0][0]]==1 :
            s0+=1
        S[0]+=B[s0][1]
        check[B[s0][0]]=1
    else :
        while check[C[s1][0]]==1 :
            s1+=1
        S[1]+=C[s1][1]
        check[C[s1][0]]=1
    #print(S)
    #print(check)
        

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

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):
    if _ % 2 == 0:
        while A:
            a, i = A[-1]
            if used[i]:
                A.pop()
                continue
            b, j = B[-1]
            if used[j]:
                B.pop()
                continue
            if a > b:
                x += a
                used[i] = True
                A.pop()
            else:
                x += OA[j][0]
                used[j] = True
                B.pop()
            break
    else:
        while B:
            b, i = B[-1]
            if used[i]:
                B.pop()
                continue
            a, j = A[-1]
            if used[j]:
                A.pop()
                continue
            if b > a:
                y += b
                used[i] = True
                B.pop()
            else:
                y += OB[j][0]
                used[j] = True
                A.pop()
            break
print(x - y)

Submission status: Wrong Answer

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

diff = [[0] for i in range(n)]
sorted_diff = [[0] for i in range(n)]

for i in range(n):
  diff[i][0] = info[i][0]+info[i][1] 

for i in range(n):
  info[i].extend(diff[i])
#print(info)

sorted_diff = sorted(info, key=lambda x: x[2],reverse=True)

#print(sorted_diff)
takahashi =0
aoki = 0
for i in range(n):
  if i%2==0:
    takahashi+= sorted_diff[0][1]
    print(sorted_diff[0][1])
    del sorted_diff[0]
  else:
    aoki+=sorted_diff[0][1]
    print(sorted_diff[0][1])
    del sorted_diff[0]
    
print(takahashi-aoki)

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = []
for _ in range(N):
    A, B = list(map(int, input().split()))
    arr.append([A, B, A-B])
arr = sorted(arr, key=lambda x: x[2])

a = 0
b = 0
for i in range(N):
    if i % 2 == 0:
        a += arr[i][0]
    else:
        b += arr[i][1]
print(a-b)

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]), reverse=True))
aoki = list(sorted(range(n), key=lambda dish: (a[dish], b[dish]), reverse=True))

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

print(x - y)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [0 for i in range(N)]
B = [0 for i in range(N)]

for i in range(N):
  A[i], B[i] = [int(j) for j in input().split()]

diff = 0

while len(A) > 0:
  index = A.index(max(A))
  diff += A[index]
  A.pop(index)
  B.pop(index)

  if len(A) == 0:
    break

  index = B.index(max(B))
  diff -= B[index]
  A.pop(index)
  B.pop(index)

print(diff)

Submission status: Wrong Answer

Solution code:
import sys

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)
    sAB = sorted(AB, key=lambda x: x[0], reverse=True)
    takahashi = sum([s[0] for s in sAB[::2]])
    aoki = sum([s[1] for s in sAB[1::2]])
    ans1 = takahashi - aoki

    sAB = sorted(AB, key=lambda x: x[1], reverse=True)
    takahashi = sum([s[0] for s in sAB[::2]])
    aoki = sum([s[1] for s in sAB[1::2]])
    ans2 = takahashi - aoki

    return max(ans1, ans2)


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

Submission status: Wrong Answer

Solution code:
def nikkei2019_qual_c():
    import numpy as np
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    ab.sort(key=lambda x: (x[1] - x[0], x[0]), reverse=True)
    ab = np.array(ab)

    print(np.sum(ab[::2, 0], dtype="int64") - np.sum(ab[1::2, 1], dtype="int64"))


nikkei2019_qual_c()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N=int(raw_input())
DA=defaultdict(list)
DB=defaultdict(list)
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()]
    DA[A].append(i)
    DB[B].append(i)
    S[i]=[A,B]
KA=sorted(DA.keys())
KB=sorted(DA.keys())
ans=0
tturn=0
sturn=1
for i in range(N):
    if KA[-1] >= KB[-1]:
        cands=DA[KA[-1]]
        scores=[S[x][1] for x in cands if notused[x]==1]
    else:
        cands=DB[KB[-1]]
        scores=[S[x][0] for x in cands if notused[x]==1]
    chosenind = cands[scores.index(max(scores))]
    notused[chosenind]=0
    DA[S[chosenind][0]].remove(chosenind)
    DB[S[chosenind][1]].remove(chosenind)
    if len(DA[S[chosenind][0]])==0:
        KA.pop(-1)
    if len(DA[S[chosenind][0]])==0:
        KB.pop(-1)
    ans += S[chosenind][tturn] * sturn
    sturn*=-1
    tturn = not(tturn)
print ans

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[0], reverse=True)

div = [[abs(ab[i][1] - ab[i][0]), ab[i][0], ab[i][1]] for i in range(n)]
div = sorted(div, key=lambda x: x[0], reverse=True)

counta = 0
countb = 0
for i in range(n):
    if i % 2 == 0:
        counta += div[i][1]
    else:
        countb += div[i][2]

print(counta - countb)

Submission status: Wrong Answer

Solution code:
#import pandas as pd
n=int(input())
O=[]
#A=[]
#B=[]
for i in range(n):
    a,b=map(int, input().split(" "))
    O.append([2*a-b,a,b])
  
O=sorted(O, key=lambda x: x[0])[::-1]
#print(O)

count=0
for num in range(n):
    if num%2==0:
        count+=O[num][1]
    else:
        count-=O[num][2]

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


diff = [[ryouri[i][1] - ryouri[i][0], i] for i in range(n)]
diff = sorted(diff, key=lambda x: x[0], reverse=True)

score_t = 0
score_k = 0

for i, x in enumerate(diff):
    if i % 2 == 0:
        score_t += ryouri[x[1]][0]
    else:
        score_k += ryouri[x[1]][1]
        
print(score_t - score_k)

Submission status: Wrong Answer

Solution code:
# C
import numpy as np
N = int(input())
a_list, b_list = [], []
diff_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
    diff_list.append(a-b)
a_list = np.asarray(a_list)
b_list = np.asarray(b_list)
diff_list = np.asarray(diff_list)
    
aoki = []
taka = []
def aoki_act(current_b, diff):
    if len(list(set(diff))) == 1:
        idx = np.argmax(current_b)
    else:
        idx = np.argmax(-diff)
    return idx
def taka_act(current_a, diff):
    if len(list(set(diff))) == 1:
        idx = np.argmax(current_a)
    else:
        idx = np.argmax(diff)
    return idx

while(len(a_list) > 0):
#     print(a_list, b_list)
    taka_idx = taka_act(a_list, diff_list)
    taka.append(a_list[taka_idx])
    a_list = np.delete(a_list, taka_idx)
    b_list = np.delete(b_list, taka_idx)
    diff_list = np.delete(diff_list, taka_idx)
#     print(a_list, b_list)

    if len(a_list) == 0:
        break
    
    aoki_idx = aoki_act(a_list, diff_list)
    aoki.append(b_list[aoki_idx])
    a_list = np.delete(a_list, aoki_idx)
    b_list = np.delete(b_list, aoki_idx)
    diff_list = np.delete(diff_list, aoki_idx)
#     print(a_list, b_list)

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

Submission status: Wrong Answer

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

n =int(input())

# n行の複数列ある数値を二次元配列へ。x[n][2]
ab = [[int(i) for i in input().split()] for i in range(n)] 

#print(ab)

ab.sort(key = lambda x: x[1]+x[0])
#print(ab)
answer = 0
for i in range(n):
    if i % 2 == 0:
        answer += ab[i][0]
    else:
        answer -= ab[i][1]
print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
Nlist=[]
Takalist=[]
Aokilist=[]
for n in range(N):
    Nlist.append(n)
    a,b = map(int,input().split())
    Takalist.append(a)
    Aokilist.append(b)

Taka = 0
Aoki = 0


flg = 0
for n in range(N):
    if flg == 0:
        big = max(Takalist)
        Taka += big
        num = Takalist.index(big)
        Aokilist[num]=0
        Takalist[num]=0
        flg=1

    elif flg == 1:
        big = max(Aokilist)
        Aoki += big
        num = Aokilist.index(big)
        Aokilist[num]=0
        Takalist[num]=0
        flg=0
print(Taka-Aoki)

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = [list(map(int,input().split())) for i in range(n)]
for i in range(n):lis[i].append(lis[i][0]-lis[i][1])

takahashi = 0
aoki = 0
lis.sort(key = lambda x:x[1],reverse=True)
  # lis.sort(key = lambda x:x[2],reverse=True)

for i in range(n):
    if i % 2 == 0:
        takahashi += lis[i][0]
    else:
        aoki += lis[i][1]
ans = takahashi-aoki

takahashi = 0
aoki = 0

lis.sort(key=lambda  x:x[0],reverse=True)
for i in range(n):
    if i % 2 == 0:
        takahashi += lis[i][0]
    else:
        aoki += lis[i][1]
ans = min(ans,takahashi-aoki)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
taka = sorted(ab, key=lambda x:(x[1], x[0]))[::-1]
ao = sorted(ab, key=lambda x:(x[0], x[1]))[::-1]
res = 0
for i in range(n):
    if i % 2 == 0: # takahashi
        res += taka[i][0]
    else: #aoki
        res -= ao[i][1]
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []
for i in range(n):
    ta, tb = map(int, input().split())
    a.append(ta)
    b.append(tb)
    
happya = 0
happyb = 0

def wa(a,b):
    return a+b

c = list(map(wa, a, b))
for i in range(n):
    c[i] = [c[i], i]
c.sort()
c.reverse()

d = []
for i in range(n):
    d.append(c[i][1])

for i in d:
    if(i % 2 == 0):
        happya += a[i]
    else:
        happyb += b[i]
        
print(happya-happyb)