Codeforces 1315C Restoring Permutation

You are given a sequence b1,b2,,bnb1,b2,…,bn . Find the lexicographically minimal permutation a1,a2,,a2na1,a2,…,a2n such that bi=min(a2i1,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 (1t1001≤t≤100 ).

The first line of each test case consists of one integer nn  — the number of elements in the sequence bb (1n1001≤n≤100 ).

The second line of each test case consists of nn different integers b1,,bnb1,…,bn  — elements of the sequence bb (1bi2n1≤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
 
5
1
1
2
4 1
3
4 1 3
4
2 3 4 5
5
1 5 7 2 8
Output
 
. 1 2 
-1 
. 4. 5. 1. 3 2. 6 
-1 
. 1. 3. 4. 5. 6. 7. 8. 9 2 10 
that Italy easy. Since there are requirements:.. 1 B I = min ( A 2 I - . 1 , A 2 I ) ., 2 possible lexicographically
#include <bits/stdc++.h>
using namespace std;
int b[205];
int out[205];
bool vis[205];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int i,j;
        int flag=1;
        memset(vis,0,sizeof(vis));
        for(i=1;i<=n;i++)
        {
            scanf("%d",&b[i]);
            vis[b[i]]=1;
            out[2*i-1]=b[i];
        }

        for(i=1;i<=n;i++)
        {
            int find=0;

            for(j=1;j<=2*n;j++)
            {
                if(vis[j])continue;
                if(j>out[2*i-1])
                {
                    out[2*i]=j;
                    find=1;
                    vis[j]=1;
                    break;
                }
            }

            if(!find)
            {
                 flag=0;
                 break;
            }
        }

        if(!flag)
        {
            cout<<-1<<endl;
            continue;
        }
        for(i=1;i<=2*n;i++)
        {
            cout<<out[i]<<' ';
        }
        cout<<endl;
    }
    return 0;
}

 

small. So it must take into bi 2i-1 of the position (observation sample also not difficult to see). Then it is small to earth to find the rest of the number, find the first number is larger than the bi a2i to fill the position, not so, then a number of returns -1. As for the correctness, then you can think, assume b array by before the number is relatively small, so the rest of miles from the small to the earth election, to ensure that the rest of the left in a large number of larger bi behind; in front of the array is assumed that b is relatively large number , after the pick-off can certainly guarantee a smaller back several bi and with it, so greedy are correct .

Guess you like

Origin www.cnblogs.com/lipoicyclic/p/12364866.html