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 heapq


def solve(N, ABs):
    # print(N, ",", ABs)
    K = 10 ** 9
    taken = {i: False for i in range(N)}
    As = [(K - ab[0], K - ab[1], i) for i, ab in enumerate(ABs)]
    Bs = [(K - ab[1], K - ab[0], i) for i, ab in enumerate(ABs)]
    heapq.heapify(As)
    heapq.heapify(Bs)
    ans = 0
    taken_count = 0
    isTakahashi = True
    while True:
        if taken_count >= N:
            break

        am = As[0]
        while taken[am[2]]:
            heapq.heappop(As)
            am = As[0]

        bm = Bs[0]
        while taken[bm[2]]:
            heapq.heappop(Bs)
            bm = Bs[0]

        aTaka = K - am[0]
        bAoki = K - bm[0]

        bTaka = K - bm[1]
        aAoki = K - am[1]

        if isTakahashi:
            if aTaka > bAoki:
                ans += aTaka
                taken[am[2]] = True
                taken_count += 1
                heapq.heappop(As)
            elif aTaka < bAoki:
                ans += bTaka
                taken[bm[2]] = True
                taken_count += 1
                heapq.heappop(Bs)
            elif aTaka == bAoki:
                if aAoki < bTaka:
                    ans += bTaka
                    taken[bm[2]] = True
                    taken_count += 1
                    heapq.heappop(Bs)
                else:
                    ans += aTaka
                    taken[am[2]] = True
                    taken_count += 1
                    heapq.heappop(As)
        else:
            if aTaka > bAoki:
                ans -= aAoki
                taken[am[2]] = True
                taken_count += 1
                heapq.heappop(As)
            elif aTaka < bAoki:
                ans -= bAoki
                taken[bm[2]] = True
                taken_count += 1
                heapq.heappop(Bs)
            else:
                if aAoki < bTaka:
                    ans -= bAoki
                    taken[bm[2]] = True
                    taken_count += 1
                    heapq.heappop(Bs)
                else:
                    ans -= aAoki
                    taken[am[2]] = True
                    taken_count += 1
                    heapq.heappop(As)

        isTakahashi = not isTakahashi

    return ans

if __name__ == "__main__":
    N = int(input())
    ABs = [tuple(map(int, input().split(" "))) for _ in range(N)]
    print(solve(N, ABs))

Submission status: Wrong Answer

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

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([B - A, -B, i])
X = sorted(X)
Y = sorted(Y)

turn = "a"
a0 = 0
b0 = -1
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[Y[b0][2]] == 0:
				bsum -= Y[b0][1]
				D[Y[b0][2]] += 1
				break
			else:
				b0 -= 1
				
		turn = "a"
	p += 1

print(asum - bsum)

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]), key=lambda x:x[0], reverse=True)
SB=sorted( sorted(S,key=lambda x:x[0]), 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]
    elif SA[aind][0]==SB[bind][1]:
        if SA[aind][1]>=SB[bind][0]:
            chosen=SA[aind][2]
        else:
            chosen=SB[bind][2]
    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:
n = input()

a = []
for i in range(int(n)):
    x = input().split()
    ix1 = int(x[0])
    ix2 = int(x[1])
    a.append([ix1, ix2, ix1 - ix2, ix2 - ix1])

tak = 0
ao = 0

for i in range(int(n)):
    e = 0
    max = 0
    maxb = 0
    if i % 2 == 0:
        for i, aa in enumerate(a):
            if max <= aa[2]:
                if maxb <= aa[0]:
                    max = aa[2]
                    e = i
                    maxb = aa[0]
        tak += a[i][0]
        a.pop(e)
    else:
        for i, aa in enumerate(a):
            if max <= aa[3]:
                if maxb <= aa[1]:
                    max = aa[3]
                    e = i
                    maxb = aa[1]
        ao += a[i][1]
        a.pop(e)

print(tak - ao)

Submission status: Wrong Answer

Solution code:
import numpy as np
ryouriNum = int(input())
score_list_a = np.empty(ryouriNum)
score_list_b = np.empty(ryouriNum)
ryouri_list = np.empty(ryouriNum)
sumPoint_A = 0
sumPoint_B = 0
a_turn = True
b_turn = False

for i in range(ryouriNum):
    inputData = input()
    splitData = inputData.split()
    a_data = int(splitData[0])
    b_data = int(splitData[1])
    score_list_a[i] = a_data
    score_list_b[i] = b_data
    ryouri_list[i] = True


for i in range(ryouriNum):
    print(score_list_a[i], score_list_b[i])

for i in range(ryouriNum):
    print(ryouri_list)
    tempList_a = score_list_a * ryouri_list
    tempList_b = score_list_b * ryouri_list

    maxPointRyouri_a_index = tempList_b.argmax()
    maxPointRyouri_b_index = tempList_a.argmax()

    if(a_turn):
        flag_b_has_same_score = False
        for i in range(ryouriNum):
            maxScore = score_list_b[maxPointRyouri_b_index]
            if(score_list_b[i] == score_list_b[maxPointRyouri_b_index]):
                if(score_list_b[i] > maxScore):
                    maxScore = score_list_b[i]
                    flag_b_has_same_score = true

        if(flag_b_has_same_score):
            print("flag_b_has_same_score")
            maxPointRyouri_a_list = np.where(score_list_a == maxScore)
            maxPointRyouri_a_index = tempList_a[maxPointRyouri_a_index].argmax(
            )

        ryouri_list[maxPointRyouri_a_index] = False
        print("a is ", maxPointRyouri_a_index, "choised", " score = ",
              score_list_a[maxPointRyouri_a_index])
        sumPoint_A += score_list_a[maxPointRyouri_a_index]
        a_turn = False
        b_turn = True
        continue

    if(b_turn):
        flag_a_has_same_score = False
        for i in range(ryouriNum):
            maxScore = score_list_a[maxPointRyouri_a_index]
            if(score_list_a[i] == score_list_a[maxPointRyouri_a_index]):
                if(score_list_a[i] > maxScore):
                    maxScore = score_list_a[i]
                    flag_a_has_same_score = true

        if(flag_a_has_same_score):
            print("flag_a_has_same_score")
            maxPointRyouri_b_list = np.where(score_list_b == maxScore)
            maxPointRyouri_b_index = tempList_b[maxPointRyouri_b_index].argmax(
            )
        ryouri_list[maxPointRyouri_b_index] = False
        print("b is ", maxPointRyouri_b_index, "choised", " score = ",
              score_list_b[maxPointRyouri_b_index])

        sumPoint_B += score_list_b[maxPointRyouri_b_index]
        b_turn = False
        a_turn = True
        continue

print(sumPoint_A - sumPoint_B)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = []
b = []

for _ in range(n):
    ta,tb = map(int, input().split())
    a.append(ta)
    b.append(tb)

a = np.array(a)
b = np.array(b)
idx = np.lexsort((a, b))[::-1]
takahashi_idx = [idx[i] for i in range(len(idx)) if i%2 == 0]
aoki_idx = [idx[i] for i in range(len(idx)) if i%2 == 1]

takahashi = []
aoki = []
    
takahashi = a[takahashi_idx]
aoki = b[aoki_idx]

print(sum(takahashi) - sum(aoki))

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]
    elif SA[aind][0]==SB[bind][1]:
        if SA[aind][1]>=SB[bind][0]:
            chosen=SA[aind][2]
        else:
            chosen=SB[bind][2]
    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:
N=int(input())
if N%2==1:
    A=[]
    for i in range(N):
        a,b=map(int,input().split())
        c=a-b
        A.append([a,-b])
    A.sort()
    ao=0
    t=0
    for j in range(N):
        if j%2==0:
            ao+=A[j][0]
        else:
            t+=A[j][1]
    print(ao+t)

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[1]-x[0],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 t:
        y=t.pop()
        while t and f[y[2]]:
            y=t.pop()
        if not f[y[2]]:
            suma+=y[1]
        f[y[2]]=1
print(sumt-suma)

Submission status: Wrong Answer

Solution code:
import numpy as np
from sys import stdin
N=int(stdin.readline().rstrip())
data=[]
for i in range(N):
    data.append([int(x) for x in stdin.readline().rstrip().split()])
data=np.array(data,dtype=np.float64)
sabun=np.absolute(data[:,0]-data[:,1])

mae=sum(data[:,0][0::2])-sum(data[:,1][1::2])
ato=sum(data[:,0][1::2])-sum(data[:,1][0::2])

if N%2==0 and len(set(data[:,0]))==1 and len(set(data[:,1]))==1:
    if mae > ato:
        print(int(mae))
    else:
        print(int(ato))
else:
    if sum(sabun)==0:
        if mae > ato:
            print(int(mae))
        else:
            print(int(ato))

    else:
        #sabun=np.sort(sabun)
        A=sum(sabun[0::2])
        B=sum(sabun[1::2])
        if (A-B) > (B-A):
            print(int(A-B))
        else:
            print(int(B-A))

Submission status: Wrong Answer

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

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

Ai = list(enumerate(A))
Bi = list(enumerate(B))

Aii = sorted(Ai, key= lambda x:x[1])
Bii = sorted(Bi, key= lambda x:x[1] )

taka = 0
aoki = 0


for i in range(N):
    if i % 2 == 0:
        taka += A[Bii[i][0]]
    else:
        aoki += B[Aii[i][0]]
        
print(taka -aoki)

Submission status: Wrong Answer

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



# print(C)

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

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

Submission status: Wrong Answer

Solution code:
import 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:B[x[1]][0], reverse=True)
A.sort(key=lambda x:x[0])
B.sort(key=lambda x:A[x[1]][0], reverse=True)
B.sort(key=lambda x:x[0])

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

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_point, B_point = 0, 0
for i in range(n):
    try:
        A_point += max(A)
        #print('A +=', max(A), A_point)
        A.remove(max(A))
        B = B[:-1]
        B_point += max(B)
        #print('B +=', max(B), B_point)
        B.remove(max(B))

    except:
        pass
print(A_point - B_point)

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(abs(sum(taka)-sum(aoki)))

Submission status: Wrong Answer

Solution code:
# coding:utf-8

N = int(input())
dish = dict()
A = dict()
B = dict()

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

def eat(d_list, n):
    if d_list[n] == 0:
        # 既に食べれらている時
        return False, d_list
    else:
        # 食べる事が可能の時
        d_list[n] = 0
        return True, d_list

# A, B を幸福度が高い順に並べ替え
A = sorted(A.items(), key=lambda x: x[1], reverse=True)
B = sorted(B.items(), key=lambda x: x[1], reverse=True)

# A, B の幸福度
a_happy, b_happy = 0, 0
# A, B の進捗状況
a_ptr, b_ptr = 0, 0

def set_key(d, l, ptr):
    eat_num = ptr
    while True:
        if d[l[eat_num][0]] == 1:
            return eat_num
        else:
            eat_num += 1

for i in range(N):
    a_key = set_key(dish, A, a_ptr)
    b_key = set_key(dish, B, b_ptr)
    a = A[a_key]
    b = B[b_key]
    if i % 2 == 0:
        if a <= b:
            ak_k = B[b_key][0]  # Bの最大幸福の皿番号
            ak_v = A[ak_k][1]
            # ak食べる
            a_happy += ak_v
            dish[ak_k] = 0
        else:
            # a を食べる
            a_happy += A[a_key][1]
            dish[A[a_key][0]] = 0
            a_ptr = a_key + 1
    else:
        if b <= a:
            bk_k = A[a_key][0]  # Bの最大幸福の皿番号
            bk_v = B[bk_k][1]
            # bk食べる
            b_happy += bk_v
            dish[bk_k] = 0
        else:
            # b を食べる
            b_happy += B[b_key][1]
            dish[B[b_key][0]] = 0
            b_ptr = b_key + 1

print(a_happy - b_happy)

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[1]-x[0],x[1]))
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 t:
        y=t.pop()
        while t and f[y[2]]:
            y=t.pop()
        if not f[y[2]]:
            suma+=y[1]
        f[y[2]]=1
print(sumt-suma)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
scoretable = [list(map(int, input().split())) for _ in range(N)]
score = [0, 0]

def revers(x):
    if x == 0:
        return 1
    if x == 1:
        return 0

for j in itertools.cycle([0, 1]):
    cash_max = [[0, 0], 0]
    for i in range(N):
        if scoretable[i][j] > cash_max[0][j]:
            cash_max = [scoretable[i], i]
        elif scoretable[i][j] == cash_max[0][j] and scoretable[i][revers(j)] > cash_max[0][revers(j)]:
            cash_max = [scoretable[i], i]
    score[j] += cash_max[0][j]
    scoretable[cash_max[1]] = [0, 0]

    N -= 1
    if N == 0:
        break


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

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict
N = int(input())
AB = [tuple(int(i) for i in input().split()) for _ in range(N)]

temp = sorted(AB, key=lambda x: x[1])
A_list = OrderedDict((i, v) for i, v in enumerate(sorted(temp, key=lambda x: x[0])))

turn = True
t_sum = 0
a_sum = 0

for _ in range(N):
    A_i, A_v = A_list.popitem()

    if turn:
        t_sum += A_v[0]
    else:
        a_sum += A_v[1]

    turn = not turn

print(t_sum - a_sum)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    a = []
    b = []
    for _ in range(N):
        ai, bi = map(int, input().split())
        a.append(ai)
        b.append(bi)
    ans = 0
    s = 1
    for _ in range(N // 2 + 1):
        if sum(a) == 0:
            print(ans)
            exit()
        ma = max(a)
        mb = max(b)
        ans += ma * s
        if ma >= mb:
            i = a.index(ma)
        else:
            i = b.index(mb)
        a[i] = 0
        b[i] = 0
        t = a
        a = b
        b = t
        s *= -1


main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
for i in range(N):
    a,b=map(int,input().split())
    c=a-b
    A.append([a,-b])
A.sort()
ao=0
t=0
for j in range(N):
    if j%2==0:
        ao+=A[j][0]
    else:
        t+=A[j][1]
print(ao+t)

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, B])

arr = sorted(arr, key=lambda x: x[1])
arr = sorted(arr, reverse=False)
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=[]
takahashi=0
aoki=0
A=0
B=0
for i in range(N):
    a,b=map(int,input().split())
    AB.append([a,b,a-b])
    A+=a
    B+=b
if A>B:
    AB.sort(key=lambda AB:(AB[2],AB[1],AB[0]))
else:
    AB.sort(key=lambda AB:(AB[2],AB[1],AB[0]),reverse=True)

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

Submission status: Wrong Answer

Solution code:
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])
ans = 0
aans,bans = 0,0
i = 0
while True:
    try:
        a = AA.popleft()
        ans += A[a]
        if BB[0] == a:
            BB.popleft()
        b = BB.popleft()
        ans -= B[b]
        if AA[0] == b:
            AA.popleft()

        i += 1
        if i >= N/2:
            break
    except:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
C = []
for i in range(N):
    a,b = [int(c) for c in input().split()]
    A.append(a)
    B.append(b)
    c = a-b if a-b != 0 else -a / 10000000000
    C.append(c)

CSortIndex = [i[0] for i in sorted(enumerate(C), key=lambda x:x[1])]

score = 0
for i in range(len(CSortIndex)):
    select = CSortIndex[i]
    if (i % 2 == 0):
        score += A[select]
    else:
        score -= B[select]

print(score)

Submission status: Wrong Answer

Solution code:
n = input()

a = []
for i in range(int(n)):
    x = input().split()
    ix1 = int(x[0])
    ix2 = int(x[1])
    a.append([ix1, ix2, ix1 - ix2, ix2 - ix1])

tak = 0
ao = 0

for i in range(int(n)):
    e = 0
    max = 0
    if i % 2 == 0:
        for i, aa in enumerate(a):
            if max <= aa[2]:
                max = aa[2]
                e = i
        tak += a[i][0]
        a.pop(e)
    else:
        for i, aa in enumerate(a):
            if max <= aa[3]:
                max = aa[3]
                e = i
        ao += a[i][1]
        a.pop(e)

print(tak - ao)

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:B[x[1]][0])
A.sort(key=lambda x:x[0])
B.sort(key=lambda x:A[x[1]][0])
B.sort(key=lambda x:x[0])

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in range(0, n):
  a.append(list(map(int, input().split())))
b = []
c = []
sumb = 0
sumc = 0
for i in range(0, n):
  b.append(a[i][0] - a[i][1])
  c.append(a[i][1] - a[i][0])
if n % 2 == 0:
  for i in range(0, int(n/2)):
    
    maxindb = b.index(max(b))
    sumb += a[maxindb][0]
    del b[maxindb]
    del c[maxindb]
    del a[maxindb]
    
    maxindc = c.index(max(c))
    sumc += a[maxindc][1]
    del b[maxindc]
    del c[maxindc]
    del a[maxindc]
    
if n % 2 != 0:
  for i in range(0, n//2):
    maxindb = b.index(max(b))
    sumb += a[maxindb][0]
    del b[maxindb]
    del c[maxindb]
    del a[maxindb]
    
    maxindc = c.index(max(c))
    sumc += a[maxindc][1]
    del b[maxindc]
    del c[maxindc]
    del a[maxindc]
    
  maxindb = b.index(max(b))
  sumb += a[maxindb][0]

result = sumb - sumc
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())

a = [0  for i in range(n)]
b = [0  for i in range(n)]
x = [[0,0,0]  for i in range(n)]

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

s=sorted(x,reverse=True)
print(s)

nu=n//2
mod=n%2

count=0
for i in range(nu):
    count+=s[i*2][1]
  #  print(count)
    count-=s[i*2+1][2]
 #   print(count)

if mod==1:
    count+=s[2*nu][1]

    

    

print(count)

Submission status: Wrong Answer

Solution code:
N = int( input())
A = [0]*N
B = [0]*N
C = [0]*N
SA = [(0,0)]*N
SB = [(0,0)]*N
for i in range(N):
    a, b = map( int, input().split())
    A[i] = a
    B[i] = b
    SA[i] = (-b,-a,i)#(-a,-abs(a-b),-a+b,-b,i)
    SB[i] = (-a,-b,i)#(-b,-abs(a-b),b-a,-a,i)
SA.sort()
SB.sort()
ansa = 0
ansb = 0
a = 0
b = 0

for i in range(N):
    if i%2 == 0:
        while 1:
           _, _,j = SA[a]
           if C[j] == 0:
                ansa += A[j]
                C[j] = 1
                a += 1
                break
           else:
                a += 1
    else:
        while 1:
            _,_,j = SB[b]
            if C[j] == 0:
                ansb += B[j]
                C[j] = 1
                b += 1
                break
            else:
                b += 1
print( ansa - ansb)

Submission status: Wrong Answer

Solution code:
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]:
            assert A[x] == C[i][0]
            res += A[x]
            taken[x] = True
            break
        # 既に取られているので後を探す
        else: i += 1
    # 青木
    while j < N:
        x = D[j][2]
        if not taken[x]:
            assert B[x] == D[j][0]
            res -= B[x]
            taken[x] = True
            break
        else: j += 1

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

print(res)

Submission status: Wrong Answer

Solution code:
N=int(input())
AB=[]
takahashi=0
aoki=0
A=0
B=0
for i in range(N):
    a,b=map(int,input().split())
    AB.append([a,b,a-b])
    A+=a
    B+=b
if A>B:
    AB.sort(key=lambda AB:(AB[2],AB[1],AB[0]),reverse=True)
else:
    AB.sort(key=lambda AB:(AB[2],AB[1],AB[0]))

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

Submission status: Wrong Answer

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

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[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 t:
        y=t.pop()
        while t and f[y[2]]:
            y=t.pop()
        if not f[y[2]]:
            suma+=y[1]
        f[y[2]]=1
print(sumt-suma)

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:B[x[1]][0])
A.sort(key=lambda x:x[0])
B.sort(key=lambda x:A[x[1]][0])
A.sort(key=lambda x:x[0])


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

Submission status: Wrong Answer

Solution code:
n = int(input())
dishes = [list(map(int, input().split())) for i in range(n)]
differences = []
for i in dishes:
    differences.append(i[1]-i[0])
differences_abs = [abs(i) for i in differences]
thappiness = 0
ahappiness = 0
while True:
    temp = [i for i, x in enumerate(differences_abs) if x == max(differences_abs)]
    if len(temp) !=1:
        list = []
        for j in temp:
            list.append(dishes[j][0])
        thappiness += max(list)
        differences.remove(max(differences))
    else:
        thappiness += dishes[temp[0]][0]
        differences.remove(max(differences))
    if len(differences)==0:
        break

    temp = [i for i, x in enumerate(differences_abs) if x == min(differences_abs)]
    if len(temp) !=1:
        list = []
        for j in temp:
            list.append(dishes[j][1])
        ahappiness += max(list)
        differences.remove(min(differences))
    else:
        ahappiness += dishes[temp[0]][1]
        differences.remove(min(differences))
    if len(differences)==0:
        break
        
print(thappiness-ahappiness)

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

ablist.sort(key=itemgetter(1, 2), 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]

ans1 = tsum - asum

# Output
print(ans1)