CF1760C.Advantage

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn participants in a competition, participant ii having a strength of sis_i.

Every participant wonders how much of an advantage they have over the other best participant. In other words, each participant ii wants to know the difference between sis_i and sjs_j, where jj is the strongest participant in the competition, not counting ii (a difference can be negative).

So, they ask you for your help! For each ii (1≤i≤n1 \leq i \leq n) output the difference between sis_i and the maximum strength of any participant other than participant ii.

共有 nn 名参赛者参加一场比赛,其中第 ii 名参赛者的实力为 sis_i。

每名参赛者都想知道:相较于除自己之外的最强参赛者,自己的优势有多大。换言之,对每名参赛者 ii,需计算 sis_i 与 sjs_j 的差值,其中 jj 是除 ii 外所有参赛者中实力最强者(该差值可为负数)。

因此,他们请求你的帮助!对每个 ii(1≤i≤n1 \leq i \leq n),输出 sis_i 与除第 ii 名参赛者外其余所有参赛者中最大实力值的差。

输入格式

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases. The descriptions of the test cases follow.

The first line of each test case contains an integer nn (2≤n≤2⋅1052 \leq n \leq 2\cdot10^5) — the length of the array.

The following line contains nn space-separated positive integers s1s_1, s2s_2, ..., sns_n (1≤si≤1091 \leq s_i \leq 10^9) — the strengths of the participants.

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

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤2⋅1052 \leq n \leq 2\cdot10^5),表示数组的长度。

接下来的一行包含 nn 个以空格分隔的正整数 s1s_1, s2s_2, ..., sns_n(1≤si≤1091 \leq s_i \leq 10^9),表示各参与者的实力值。

保证所有测试用例的 nn 值之和不超过 2⋅1052\cdot10^5。

输出格式

For each test case, output nn space-separated integers. For each ii (1≤i≤n1 \leq i \leq n) output the difference between sis_i and the maximum strength of any other participant.

对于每个测试用例,输出 nn 个以空格分隔的整数。对于每个 ii(1≤i≤n1 \leq i \leq n),输出 sis_i 与其余任意参赛者最大实力值的差。

输入输出样例

  • 输入#1

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

    输出#1

    -3 2 -4 -2 
    -1 1 
    -4 -3 -2 -1 1 
    -5 5 -5 
    0 0 0 0

说明/提示

For the first test case:

  • The first participant has a strength of 44 and the largest strength of a participant different from the first one is 77, so the answer for the first participant is 4−7=−34 - 7 = -3.
  • The second participant has a strength of 77 and the largest strength of a participant different from the second one is 55, so the answer for the second participant is 7−5=27 - 5 = 2.
  • The third participant has a strength of 33 and the largest strength of a participant different from the third one is 77, so the answer for the third participant is 3−7=−43 - 7 = -4.
  • The fourth participant has a strength of 55 and the largest strength of a participant different from the fourth one is 77, so the answer for the fourth participant is 5−7=−25 - 7 = -2.

对于第一个测试用例:

  • 第一位参与者的实力为 44,其余参与者中实力最大的为 77,因此第一位参与者的答案为 4−7=−34 - 7 = -3。
  • 第二位参与者的实力为 77,其余参与者中实力最大的为 55,因此第二位参与者的答案为 7−5=27 - 5 = 2。
  • 第三位参与者的实力为 33,其余参与者中实力最大的为 77,因此第三位参与者的答案为 3−7=−43 - 7 = -4。
  • 第四位参与者的实力为 55,其余参与者中实力最大的为 77,因此第四位参与者的答案为 5−7=−25 - 7 = -2。

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

首页