CF1038C.Gambling

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Two players A and B have a list of nn integers each. They both want to maximize the subtraction between their score and their opponent's score.

In one turn, a player can either add to his score any element from his list (assuming his list is not empty), the element is removed from the list afterward. Or remove an element from his opponent's list (assuming his opponent's list is not empty).

Note, that in case there are equal elements in the list only one of them will be affected in the operations above. For example, if there are elements 1,2,2,3{1, 2, 2, 3} in a list and you decided to choose 22 for the next turn, only a single instance of 22 will be deleted (and added to the score, if necessary).

The player A starts the game and the game stops when both lists are empty. Find the difference between A's score and B's score at the end of the game, if both of the players are playing optimally.

Optimal play between two players means that both players choose the best possible strategy to achieve the best possible outcome for themselves. In this problem, it means that each player, each time makes a move, which maximizes the final difference between his score and his opponent's score, knowing that the opponent is doing the same.

两名玩家 A 和 B 各自拥有一组包含 nn 个整数的列表。双方均希望最大化自己得分与对手得分之间的差值。

在一轮操作中,一名玩家可执行以下两种操作之一(前提是相应列表非空):

  • 将自己列表中的任意一个元素加到自己的得分上(该元素随后将从列表中移除);
  • 从对手的列表中移除任意一个元素。

注意:若列表中存在相等的元素,则上述操作每次仅影响其中一个副本。例如,若某列表为 {1,2,2,3}\{1, 2, 2, 3\},而当前轮次选择 22,则仅有一个 22 被删除(若为加至得分的操作,则该 22 同时被加入得分)。

玩家 A 先手,当双方列表均为空时游戏结束。假设双方均以最优策略进行游戏,求游戏结束时 A 的得分与 B 的得分之差。

此处“双方均以最优策略进行游戏”是指:双方始终采用能为自己带来最优结果的最佳策略。本题中即指:每位玩家在每一步操作中,均会选择使最终自身得分与对手得分之差最大化的行动,且其决策基于对手也将采取同样最优策略这一前提。

输入格式

The first line of input contains an integer nn (1≤n≤100 0001 \le n \le 100\,000) — the sizes of the list.

The second line contains nn integers aia_i (1≤ai≤1061 \le a_i \le 10^6), describing the list of the player A, who starts the game.

The third line contains nn integers bib_i (1≤bi≤1061 \le b_i \le 10^6), describing the list of the player B.

输入的第一行包含一个整数 nn(1≤n≤100 0001 \le n \le 100\,000)—— 表示列表的长度。

第二行包含 nn 个整数 aia_i(1≤ai≤1061 \le a_i \le 10^6),描述先手玩家 A 的列表。

第三行包含 nn 个整数 bib_i(1≤bi≤1061 \le b_i \le 10^6),描述玩家 B 的列表。

输出格式

Output the difference between A's score and B's score (A−BA-B) if both of them are playing optimally.

输出在双方都采取最优策略的情况下,A 的得分与 B 的得分之差(A−BA-B)。

输入输出样例

  • 输入#1

    2
    1 4
    5 1

    输出#1

    0
  • 输入#2

    3
    100 100 100
    100 100 100

    输出#2

    0
  • 输入#3

    2
    2 1
    5 6

    输出#3

    -3

说明/提示

In the first example, the game could have gone as follows:

  • A removes 55 from B's list.
  • B removes 44 from A's list.
  • A takes his 11.
  • B takes his 11.

Hence, A's score is 11, B's score is 11 and difference is 00.

There is also another optimal way of playing:

  • A removes 55 from B's list.
  • B removes 44 from A's list.
  • A removes 11 from B's list.
  • B removes 11 from A's list.

The difference in the scores is still 00.

In the second example, irrespective of the moves the players make, they will end up with the same number of numbers added to their score, so the difference will be 00.

在第一个例子中,游戏可能按如下方式进行:

  • A 从 B 的列表中移除 55。
  • B 从 A 的列表中移除 44。
  • A 取走自己的 11。
  • B 取走自己的 11。

因此,A 的得分为 11,B 的得分为 11,差值为 00。

还存在另一种最优的进行方式:

  • A 从 B 的列表中移除 55。
  • B 从 A 的列表中移除 44。
  • A 从 B 的列表中移除 11。
  • B 从 A 的列表中移除 11。

此时得分差值仍为 00。

在第二个例子中,无论双方如何行动,最终各自加入得分的数字个数都相同,因此差值恒为 00。

输入解题思路,AI测评打分。不知道怎么写?

首页