链接:https://codeforces.ml/contest/1315/problem/C
You are given a sequence b1,b2,…,bnb1,b2,…,bn. Find the lexicographically minimal permutation a1,a2,…,a2na1,a2,…,a2n such that bi=min(a2i−1,a2i)bi=min(a2i−1,a2i), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases tt (1≤t≤1001≤t≤100).
The first line of each test case consists of one integer nn — the number of elements in the sequence bb (1≤n≤1001≤n≤100).
The second line of each test case consists of nn different integers b1,…,bnb1,…,bn — elements of the sequence bb (1≤bi≤2n1≤bi≤2n).
It is guaranteed that the sum of nn by all test cases doesn't exceed 100100.
Output
For each test case, if there is no appropriate permutation, print one number −1−1.
Otherwise, print 2n2n integers a1,…,a2na1,…,a2n — required lexicographically minimal permutation of numbers from 11 to 2n2n.
Example
input
Copy
5 1 1 2 4 1 3 4 1 3 4 2 3 4 5 5 1 5 7 2 8
output
Copy
1 2 -1 4 5 1 2 3 6 -1 1 3 5 6 7 9 2 4 8 10
代码:
#include<bits/stdc++.h>
using namespace std;
long long n,t,r,q,k,s,max1=0,p;
long long a[10001],b[10001];
map<long long ,long long>m;
int main()
{
cin>>t;
while(t--)
{
cin>>n;
m.clear();
for(int i=1;i<=n;i++)
{
cin>>b[i];
m[b[i]]=1;
}
int flag=1;
for(int i=1;i<=n;i++)
{
a[i*2-1]=b[i];
k=b[i];
while(m[k]==1)
{
k++;
}
if(k<=2*n)
{
a[i*2]=k;
m[k]=1;
}
else
{
flag=0;
break;
}
}
if(flag==0)
{
cout<<-1<<endl;
}
else
{
for(int i=1;i<=2*n;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
}
}
}