A15513 | Advantage
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are $n$ participants in a competition, participant $i$ having a strength of $s_i$ .
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 $s_i$ and $s_j$ , 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 \leq i \leq n$ ) output the difference between $s_i$ and the maximum strength of any participant other than participant $i$ .
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 $s_i$ and $s_j$ , 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 \leq i \leq n$ ) output the difference between $s_i$ and the maximum strength of any participant other than participant $i$ .
输入格式
The input consists of multiple test cases. The first line contains an integer $t$ ( $1 \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 $n$ ( $2 \leq n \leq 2\cdot10^5$ ) — the length of the array.
The following line contains $n$ space-separated positive integers $s_1$ , $s_2$ , ..., $s_n$ ( $1 \leq s_i \leq 10^9$ ) — the strengths of the participants.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot10^5$ .
The first line of each test case contains an integer $n$ ( $2 \leq n \leq 2\cdot10^5$ ) — the length of the array.
The following line contains $n$ space-separated positive integers $s_1$ , $s_2$ , ..., $s_n$ ( $1 \leq s_i \leq 10^9$ ) — the strengths of the participants.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot10^5$ .
输出格式
For each test case, output $n$ space-separated integers. For each $i$ ( $1 \leq i \leq n$ ) output the difference between $s_i$ and the maximum strength of any other participant.
输入输出样例
输入 #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$ .
- 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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted