P26832 [AtCoder] Different Strokes
普及
题目描述

Problem Description

There are $ N $ dishes placed in front of Takahashi and Aoki. For convenience, these dishes are referred to as Dish $ 1 $, Dish $ 2 $, ..., Dish $ N $.

When Takahashi eats Dish $ i $, he gains $ A_i $ points of happiness. Also, when Aoki eats Dish $ i $, she gains $ B_i $ points of happiness.

They take turns starting with Takahashi, and each selects one dish at a time to eat until all dishes are exhausted. Both of them aim to maximize the difference between the total happiness they gain and the total happiness their opponent gains.

What is the value obtained by subtracting the total happiness Aoki gains from the total happiness Takahashi gains?

Input Format

The input is given from the standard input in the following format:

$ N $ $ A_1 $ $ B_1 $ $ : $ $ A_N $ $ B_N $

Output Format

Output the value obtained by subtracting the total happiness Aoki gains from the total happiness Takahashi gains.

Sample Input and Output

Sample Input #1

3
10 10
20 20
30 30

Sample Output #1

20

Sample Input #2

3
20 10
20 20
20 30

Sample Output #2

20

Sample Input #3

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

Sample Output #3

-2999999997

Notes/Hints

Constraints

  • $1 \leq N \leq 10^5$
  • $1 \leq A_i \leq 10^9$
  • $1 \leq B_i \leq 10^9$
  • All input values are integers.

Sample Explanation 1

In this example, both of them gain $ 10 $ points from Dish $ 1 $, $ 20 $ points from Dish $ 2 $, and $ 30 $ points from Dish $ 3 $. Since their preferences match, they always choose the dish that provides the most happiness from the remaining dishes. Therefore, Takahashi first chooses Dish $ 3 $, then Aoki chooses Dish $ 2 $, and finally Takahashi chooses Dish $ 1 $. The answer is $ (30 + 10) - 20 = 20 $.

Sample Explanation 2

In this example, Takahashi gains $ 20 $ points from any of the dishes $ 1, 2, 3 $, but Aoki gains $ 10 $ points from Dish $ 1 $, $ 20 $ points from Dish $ 2 $, and $ 30 $ points from Dish $ 3 $. Since only Aoki has preferences for the dishes, they always choose the dish that provides Aoki the most happiness from the remaining dishes. Therefore, Takahashi first chooses Dish $ 3 $, then Aoki chooses Dish $ 2 $, and finally Takahashi chooses Dish $ 1 $. The answer is $ (20 + 20) - 20 = 20 $.

Sample Explanation 3

The answer may not fit into a 32-bit integer.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 10 10 20 20 30 30
样例输出
20