CF1872D.Plus Minus Permutation

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given 33 integers — nn, xx, yy. Let's call the score of a permutation†^\dagger p1,…,pnp_1, \ldots, p_n the following value:

(p_1cdotx+p_2cdotx+ldots+p_lfloorfracnxrfloorcdotx)−(p_1cdoty+p_2cdoty+ldots+p_lfloorfracnyrfloorcdoty)(p\_{1 \\cdot x} + p\_{2 \\cdot x} + \\ldots + p\_{\\lfloor \\frac{n}{x} \\rfloor \\cdot x}) - (p\_{1 \\cdot y} + p\_{2 \\cdot y} + \\ldots + p\_{\\lfloor \\frac{n}{y} \\rfloor \\cdot y})

In other words, the score of a permutation is the sum of pip_i for all indices ii divisible by xx, minus the sum of pip_i for all indices ii divisible by yy.

You need to find the maximum possible score among all permutations of length nn.

For example, if n=7n = 7, x=2x = 2, y=3y = 3, the maximum score is achieved by the permutation [2,6‾,1‾,7‾,5,4‾‾,3][2,\color{red}{\underline{\color{black}{6}}},\color{blue}{\underline{\color{black}{1}}},\color{red}{\underline{\color{black}{7}}},5,\color{blue}{\underline{\color{red}{\underline{\color{black}{4}}}}},3] and is equal to (6+7+4)−(1+4)=17−5=12(6 + 7 + 4) - (1 + 4) = 17 - 5 = 12.

†^\dagger A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in any order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (the number 22 appears twice in the array) and [1,3,4][1,3,4] is also not a permutation (n=3n=3, but the array contains 44).

给你 33 个整数:nn、xx、yy。我们定义一个排列†^\dagger p1,…,pnp_1, \ldots, p_n 的得分为如下值:

(p1⋅x+p2⋅x+…+p⌊nx⌋⋅x)−(p1⋅y+p2⋅y+…+p⌊ny⌋⋅y)(p_{1 \cdot x} + p_{2 \cdot x} + \ldots + p_{\lfloor \frac{n}{x} \rfloor \cdot x}) - (p_{1 \cdot y} + p_{2 \cdot y} + \ldots + p_{\lfloor \frac{n}{y} \rfloor \cdot y})

换言之,一个排列的得分等于所有下标 ii(满足 ii 被 xx 整除)对应的 pip_i 之和,减去所有下标 ii(满足 ii 被 yy 整除)对应的 pip_i 之和。

你需要在所有长度为 nn 的排列中,找出可能的最大得分。

例如,当 n=7n = 7、x=2x = 2、y=3y = 3 时,最大得分由排列 [2,6‾,1‾,7‾,5,4‾‾,3][2,\color{red}{\underline{\color{black}{6}}},\color{blue}{\underline{\color{black}{1}}},\color{red}{\underline{\color{black}{7}}},5,\color{blue}{\underline{\color{red}{\underline{\color{black}{4}}}}},3] 实现,其得分为 (6+7+4)−(1+4)=17−5=12(6 + 7 + 4) - (1 + 4) = 17 - 5 = 12。

†^\dagger 长度为 nn 的排列是指由 11 到 nn 这 nn 个互不相同的整数以任意顺序组成的数组。例如,[2,3,1,5,4][2,3,1,5,4] 是一个排列,但 [1,2,2][1,2,2] 不是排列(数字 22 在数组中出现了两次),[1,3,4][1,3,4] 也不是排列(此时 n=3n=3,但数组中包含了 44)。

输入格式

The first line of input contains an integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

Then follows the description of each test case.

The only line of each test case description contains 33 integers nn, xx, yy (1≤n≤1091 \le n \le 10^9, 1≤x,y≤n1 \le x, y \le n).

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

接下来是每个测试用例的描述。

每个测试用例的描述仅有一行,包含 33 个整数 nn、xx、yy(1≤n≤1091 \le n \le 10^9,1≤x,y≤n1 \le x, y \le n)。

输出格式

For each test case, output a single integer — the maximum score among all permutations of length nn.

对于每个测试用例,输出一个整数——所有长度为 nn 的排列中的最大得分。

输入输出样例

  • 输入#1

    8
    7 2 3
    12 6 3
    9 1 9
    2 2 2
    100 20 50
    24 4 6
    1000000000 5575 25450
    4 4 1

    输出#1

    12
    -3
    44
    0
    393
    87
    179179179436104
    -6

说明/提示

The first test case is explained in the problem statement above.

In the second test case, one of the optimal permutations will be [12,11,2‾,4,8,9‾‾,10,6,1‾,5,3,7‾‾][12,11,\color{blue}{\underline{\color{black}{2}}},4,8,\color{blue}{\underline{\color{red}{\underline{\color{black}{9}}}}},10,6,\color{blue}{\underline{\color{black}{1}}},5,3,\color{blue}{\underline{\color{red}{\underline{\color{black}{7}}}}}]. The score of this permutation is (9+7)−(2+9+1+7)=−3(9 + 7) - (2 + 9 + 1 + 7) = -3. It can be shown that a score greater than −3-3 can not be achieved. Note that the answer to the problem can be negative.

In the third test case, the score of the permutation will be (p1+p2+…+p9)−p9(p_1 + p_2 + \ldots + p_9) - p_9. One of the optimal permutations for this case is [9,8,7,6,5,4,3,2,1][9, 8, 7, 6, 5, 4, 3, 2, 1], and its score is 4444. It can be shown that a score greater than 4444 can not be achieved.

In the fourth test case, x=yx = y, so the score of any permutation will be 00.

第一个测试用例已在题目描述中说明。

在第二个测试用例中,一个最优排列为 [12,11,2‾,4,8,9‾‾,10,6,1‾,5,3,7‾‾][12,11,\color{blue}{\underline{\color{black}{2}}},4,8,\color{blue}{\underline{\color{red}{\underline{\color{black}{9}}}}},10,6,\color{blue}{\underline{\color{black}{1}}},5,3,\color{blue}{\underline{\color{red}{\underline{\color{black}{7}}}}}]。该排列的得分为 (9+7)−(2+9+1+7)=−3(9 + 7) - (2 + 9 + 1 + 7) = -3。可以证明,无法获得大于 −3-3 的得分。注意:本题的答案可以为负数。

在第三个测试用例中,排列的得分为 (p1+p2+…+p9)−p9(p_1 + p_2 + \ldots + p_9) - p_9。该情况的一个最优排列是 [9,8,7,6,5,4,3,2,1][9, 8, 7, 6, 5, 4, 3, 2, 1],其得分为 4444。可以证明,无法获得大于 4444 的得分。

在第四个测试用例中,x=yx = y,因此任意排列的得分均为 00。

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

首页