A14584 | Bob's Beautiful Array
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Bob really likes playing with arrays of numbers. That's why for his birthday, his friends bought him a really interesting machine – an array beautifier.
The array beautifier takes an array $A$ consisting of $N$ integers, and it outputs a new array $B$ of length N that it constructed based on the array given to it. The array beautifier constructs the new array in the following way: it takes two numbers at different indices from the original array and writes their sum to the end of the new array. It does this step $N$ times - resulting in an output array of length $N$ . During this process, the machine can take the same index multiple times in different steps.
Bob was very excited about the gift that his friends gave him, so he put his favorite array in the machine. However, when the machine finished, Bob was not happy with the resulting array. He misses his favorite array very much, and hopes to get it back.
Given the array that the machine outputted, help Bob find an array that could be the original array that he put in the machine. Sometimes the machine makes mistakes, so it is possible that no appropriate input array exists for the array it has outputted. In such case, let Bob know that his array is forever lost.
The array beautifier takes an array $A$ consisting of $N$ integers, and it outputs a new array $B$ of length N that it constructed based on the array given to it. The array beautifier constructs the new array in the following way: it takes two numbers at different indices from the original array and writes their sum to the end of the new array. It does this step $N$ times - resulting in an output array of length $N$ . During this process, the machine can take the same index multiple times in different steps.
Bob was very excited about the gift that his friends gave him, so he put his favorite array in the machine. However, when the machine finished, Bob was not happy with the resulting array. He misses his favorite array very much, and hopes to get it back.
Given the array that the machine outputted, help Bob find an array that could be the original array that he put in the machine. Sometimes the machine makes mistakes, so it is possible that no appropriate input array exists for the array it has outputted. In such case, let Bob know that his array is forever lost.
输入格式
The first line contains one positive integer $N$ ( $2 \leq N \leq 10^3$ ) – the length of Bob's array.
The second line contains $N$ integers $B_1$ , $B_2$ , ..., $B_N$ ( $1 \leq B_i \leq 10^6$ ) – the elements of the array the machine outputted.
The second line contains $N$ integers $B_1$ , $B_2$ , ..., $B_N$ ( $1 \leq B_i \leq 10^6$ ) – the elements of the array the machine outputted.
输出格式
If an appropriate input array exists, print "YES", followed by the input array $A_1$ , $A_2$ , ..., $A_N$ ( $-10^9 \leq A_i \leq 10^9$ ) in the next line. Otherwise, print "NO".
输入输出样例
输入 #1
2 5 5
输出 #1
YES 2 3
输入 #2
3 1 2 3
输出 #2
YES 0 1 2
输入 #3
3 2 4 5
输出 #3
NO
输入 #4
4 1 3 5 7
输出 #4
YES 6 -3 4 1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted