CF2147D.Game on Array

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array aa of nn positive integers. Alice and Bob will play a game with this array. They will take alternating turns, with Alice going first.

At each turn, the player must choose a value x>0x \gt 0 that appears in aa at least once. Then,

  1. the player earns 11 point for each value xx in the array,
  2. each value xx in the array is decreased by 11 and becomes x−1x-1.

Note that the player can choose xx only if it is present in aa at the moment, so each valid move earns a positive amount of points. For example, if the array is [3,8,5,8][3,8,5,8] and Alice chooses x=8x=8, the array will become [3,7,5,7][3,7,5,7] and Alice will earn 22 points.

The game ends when no xx can be chosen; that is, when all the elements in the array are zero.

Given that both players want to maximize their points and play optimally, calculate the amount of points that each player will end up with.

给你一个包含 nn 个正整数的数组 aa。Alice 和 Bob 将用这个数组进行一场游戏。他们将轮流行动,Alice 先手。

在每一轮中,当前玩家必须选择一个值 x>0x \gt 0,该值至少在数组 aa 中出现一次。然后:

  1. 当前玩家对数组中每一个值为 xx 的元素获得 11 分;
  2. 数组中每一个值为 xx 的元素均减 11,变为 x−1x-1。

注意:玩家只能选择当前存在于数组 aa 中的 xx,因此每一次合法操作都必然获得正数分数。例如,若数组为 [3,8,5,8][3,8,5,8],且 Alice 选择了 x=8x=8,则数组将变为 [3,7,5,7][3,7,5,7],Alice 将获得 22 分。

当无法再选择任何 xx(即数组中所有元素均为 00)时,游戏结束。

假设双方均希望最大化自己的得分,且均以最优策略进行游戏,请计算双方最终各自获得的分数。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1031 \le t \le 10^3). The description of the test cases follows.

The first line of each test case contains an integer nn (1≤n≤2⋅1051 \leq n \leq 2\cdot 10^{5}) — the size of the array.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \leq a_i \leq 10^{9}) — the elements of the array.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052\cdot 10^{5}.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1031 \le t \le 10^3)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2\cdot 10^{5})—— 数组的大小。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \leq a_i \leq 10^{9})—— 数组的元素。

保证所有测试用例的 nn 之和不超过 2⋅1052\cdot 10^{5}。

输出格式

For each test case, output two integers, the amount of points Alice and Bob will get if both play optimally.

对于每个测试用例,输出两个整数,分别表示爱丽丝和鲍勃在双方均采取最优策略时各自获得的分数。

输入输出样例

  • 输入#1

    3
    3
    2 1 1
    5
    3 3 3 5 5
    4
    9 9 9 9

    输出#1

    3 1
    10 9
    20 16

说明/提示

Visualizer link

In the first test case, Alice chooses x=1x=1 with her first move. The array becomes [2,0,0][2,0,0] and she earns 22 points. After that, Bob is forced to choose x=2x=2. The array becomes [1,0,0][1,0,0] and Bob earns 11 point. Finally, Alice is forced to choose x=1x=1 and earn one more point. After that, the array is [0,0,0][0,0,0], so the game ends. In total, Alice finishes with 33 points and Bob with 11 point.

In the third test case, each player will decrement all the elements and earn 44 points each move. Alice will earn 5⋅4=205 \cdot 4 = 20 points while Bob will only earn 4⋅4=164\cdot 4 = 16 points.

可视化链接

在第一个测试用例中,Alice 第一步选择 x=1x=1。数组变为 [2,0,0][2,0,0],她获得 22 分。随后,Bob 被迫选择 x=2x=2。数组变为 [1,0,0][1,0,0],Bob 获得 11 分。最后,Alice 被迫选择 x=1x=1 并再获得 11 分。此后,数组变为 [0,0,0][0,0,0],游戏结束。最终,Alice 共获得 33 分,Bob 获得 11 分。

在第三个测试用例中,每位玩家每步都将所有元素减 11,并各获得 44 分。Alice 将获得 5⋅4=205 \cdot 4 = 20 分,而 Bob 仅获得 4⋅4=164\cdot 4 = 16 分。

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

首页