CF1599J.Bob's Beautiful Array
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
鲍勃非常喜欢玩数字数组。因此,在他生日时,朋友们送给他一台非常有趣的机器——数组美化器。
数组美化器接收一个由 N 个整数构成的数组 A,并输出一个长度为 N 的新数组 B,该数组是根据输入数组构造而成的。数组美化器按如下方式构造新数组:它从原始数组中选取两个下标不同的数,并将它们的和追加到新数组的末尾。这一操作重复执行 N 次,最终得到一个长度为 N 的输出数组。在整个过程中,机器在不同步骤中可以多次选取同一个下标(即允许重复使用同一位置的元素,但每一步中所选的两个下标必须互异)。
鲍勃对朋友们送给他的这份礼物感到异常兴奋,于是将他最钟爱的数组输入了这台机器。然而,当机器完成处理后,鲍勃却对输出的数组非常不满意。他十分怀念自己心爱的原始数组,并希望能将其恢复出来。
现给定机器输出的数组,请你帮助鲍勃找出一个可能的原始输入数组。有时机器会出现故障,因此对于给定的输出数组,可能存在没有任何合法输入数组能产生它的情况。此时,请告诉鲍勃:他的数组已永远丢失。
输入格式
The first line contains one positive integer N (2≤N≤103) – the length of Bob's array.
The second line contains N integers B1, B2, ..., BN (1≤Bi≤106) – the elements of the array the machine outputted.
第一行包含一个正整数 N(2≤N≤103)——即 Bob 数组的长度。
第二行包含 N 个整数 B1, B2, ..., BN(1≤Bi≤106)——即该机器输出的数组元素。
输出格式
If an appropriate input array exists, print "YES", followed by the input array A1, A2, ..., AN (−109≤Ai≤109) in the next line. Otherwise, print "NO".
如果存在合适的输入数组,则输出 "YES",并在下一行输出输入数组 A1, A2, ..., AN(其中 −109≤Ai≤109);否则输出 "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
输入解题思路,AI测评打分。不知道怎么写?