Omkar has received a message from Anton saying “Your story for problem
A is confusing. Just make a formal statement.” Because of this, Omkar
gives you an array 𝑎=[𝑎1,𝑎2,…,𝑎𝑛] of 𝑛 distinct integers. An
array 𝑏=[𝑏1,𝑏2,…,𝑏𝑘] is called nice if for any two distinct
elements 𝑏𝑖,𝑏𝑗 of 𝑏, |𝑏𝑖−𝑏𝑗| appears in 𝑏 at least once. In
addition, all elements in 𝑏 must be distinct. Can you add several
(maybe, 0) integers to 𝑎 to create a nice array 𝑏 of size at most
300? If 𝑎 is already nice, you don’t have to add any elements.For example, array [3,6,9] is nice, as |6−3|=|9−6|=3, which appears in
the array, and |9−3|=6, which appears in the array, while array
[4,2,0,6,9] is not nice, as |9−4|=5 is not present in the array.For integers 𝑥 and 𝑦, |𝑥−𝑦|=𝑥−𝑦 if 𝑥>𝑦 and |𝑥−𝑦|=𝑦−𝑥
otherwise.Input Each test contains multiple test cases. The first line contains
𝑡 (1≤𝑡≤50), the number of test cases. Description of the test cases
follows.The first line of each test case contains a single integer 𝑛
(2≤𝑛≤100) — the length of the array 𝑎.The second line of each test case contains 𝑛 distinct integers
𝑎1,𝑎2,⋯,𝑎𝑛 (−100≤𝑎𝑖≤100) — the elements of the array 𝑎.Output For each test case, output one line containing YES if Omkar can
create a nice array 𝑏 by adding elements to 𝑎 and NO otherwise. The
case of each letter does not matter, so yEs and nO will also be
accepted.If the first line is YES, output a second line containing a single
integer 𝑘 (𝑛≤𝑘≤300).Then output one line containing 𝑘 distinct integers 𝑏1,𝑏2,⋯,𝑏𝑘
(−109≤𝑏𝑖≤109), the elements of the nice array 𝑏. 𝑏1,𝑏2,⋯,𝑏𝑘 can
be in any order. For each 𝑎𝑖 in 𝑎, 𝑎𝑖 must appear at least once
in 𝑏.It can be proved that if Omkar can create such an array 𝑏, then he
can also do so in a way that satisfies the above constraints.If multiple solutions exist, you can print any.
Example inputCopy 4 3 3 0 9 2 3 4 5
-7 3 13 -2 8 4 4 8 12 6 outputCopy yes 4 6 0 3 9 yEs 5 5 3 1 2 4 NO Yes 6 8 12 6 2 4 10 Note For the first case, you can add integers to
𝑎 to receive the array 𝑏=[6,0,3,9]. Note that |6−3|=|9−6|=|3−0|=3
and 3 is in 𝑏, |6−0|=|9−3|=6 and 6 is in 𝑏, and |9−0|=9 is in 𝑏, so
𝑏 is nice.For the second case, you can add integers to 𝑎 to receive the array
𝑏=[5,3,1,2,4]. We have that |2−1|=|3−2|=|4−3|=|5−4|=1 is in 𝑏,
|3−1|=|4−2|=|5−3|=2 is in 𝑏, |4−1|=|5−2|=3 is in 𝑏, and |5−1|=4 is
in 𝑏, so 𝑏 is nice.For the fourth case, you can add integers to 𝑎 to receive the array
𝑏=[8,12,6,2,4,10]. We have that |4−2|=|6−4|=|8−6|=|10−8|=|12−10|=2 is
in 𝑏, |6−2|=|8−4|=|10−6|=|12−8|=4 is in 𝑏, |8−2|=|10−4|=|12−6|=6 is
in 𝑏, |10−2|=|12−4|=8 is in 𝑏, and |12−2|=10 is in 𝑏, so 𝑏 is
nice.It can be proven that for all other test cases it is impossible to
create a nice array 𝑏.
注意看题目范围。。
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
const int maxn=105;
int a[maxn];
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
memset(a,0,sizeof(0));
int flag=1;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]<0)flag=0;
}
sort(a+1,a+1+n);
if(flag==0)
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
cout<<a[n]+1<<endl;
for(int i=0;i<=a[n];i++)
{
cout<<i<<" ";
}
cout<<endl;
}
}
}