CF1760C.Advantage
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n participants in a competition, participant i having a strength of si.
Every participant wonders how much of an advantage they have over the other best participant. In other words, each participant i wants to know the difference between si and sj, where j is the strongest participant in the competition, not counting i (a difference can be negative).
So, they ask you for your help! For each i (1≤i≤n) output the difference between si and the maximum strength of any participant other than participant i.
共有 n 名参赛者参加一场比赛,其中第 i 名参赛者的实力为 si。
每名参赛者都想知道:相较于除自己之外的最强参赛者,自己的优势有多大。换言之,对每名参赛者 i,需计算 si 与 sj 的差值,其中 j 是除 i 外所有参赛者中实力最强者(该差值可为负数)。
因此,他们请求你的帮助!对每个 i(1≤i≤n),输出 si 与除第 i 名参赛者外其余所有参赛者中最大实力值的差。
输入格式
The input consists of multiple test cases. The first line contains an integer t (1≤t≤1000) — the number of test cases. The descriptions of the test cases follow.
The first line of each test case contains an integer n (2≤n≤2⋅105) — the length of the array.
The following line contains n space-separated positive integers s1, s2, ..., sn (1≤si≤109) — the strengths of the participants.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
输入包含多个测试用例。第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(2≤n≤2⋅105),表示数组的长度。
接下来的一行包含 n 个以空格分隔的正整数 s1, s2, ..., sn(1≤si≤109),表示各参与者的实力值。
保证所有测试用例的 n 值之和不超过 2⋅105。
输出格式
For each test case, output n space-separated integers. For each i (1≤i≤n) output the difference between si and the maximum strength of any other participant.
对于每个测试用例,输出 n 个以空格分隔的整数。对于每个 i(1≤i≤n),输出 si 与其余任意参赛者最大实力值的差。
输入输出样例
输入#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 4 and the largest strength of a participant different from the first one is 7, so the answer for the first participant is 4−7=−3.
- The second participant has a strength of 7 and the largest strength of a participant different from the second one is 5, so the answer for the second participant is 7−5=2.
- The third participant has a strength of 3 and the largest strength of a participant different from the third one is 7, so the answer for the third participant is 3−7=−4.
- The fourth participant has a strength of 5 and the largest strength of a participant different from the fourth one is 7, so the answer for the fourth participant is 5−7=−2.
对于第一个测试用例:
- 第一位参与者的实力为 4,其余参与者中实力最大的为 7,因此第一位参与者的答案为 4−7=−3。
- 第二位参与者的实力为 7,其余参与者中实力最大的为 5,因此第二位参与者的答案为 7−5=2。
- 第三位参与者的实力为 3,其余参与者中实力最大的为 7,因此第三位参与者的答案为 3−7=−4。
- 第四位参与者的实力为 5,其余参与者中实力最大的为 7,因此第四位参与者的答案为 5−7=−2。
输入解题思路,AI测评打分。不知道怎么写?