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

 
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 2 3 6
-1
1 3 5 6 7 9 2 4 8 10
题意很简单。因为有要求:1.bi=min(a2i−1,a2i),2.字典序尽可能
#include <bits/stdc++.h>
using namespace std;
int b[];
int out[];
bool vis[];
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int i,j;
int flag=;
memset(vis,,sizeof(vis));
for(i=;i<=n;i++)
{
scanf("%d",&b[i]);
vis[b[i]]=;
out[*i-]=b[i];
} for(i=;i<=n;i++)
{
int find=; for(j=;j<=*n;j++)
{
if(vis[j])continue;
if(j>out[*i-])
{
out[*i]=j;
find=;
vis[j]=;
break;
}
} if(!find)
{
flag=;
break;
}
} if(!flag)
{
cout<<-<<endl;
continue;
}
for(i=;i<=*n;i++)
{
cout<<out[i]<<' ';
}
cout<<endl;
}
return ;
}
小。所以肯定要把bi放到2i-1的位置(观察样例也不难看出)。然后就是在剩下的数里从小到大地找,找到第一个比bi大的数填到a2i的位置,没有这么一个数的话返回-1.至于正确性的话可以这么想,假设b数组里靠前的是比较小的数,那么从剩下的数里从小到大地选,能保证剩下的里较大的数留给后面更大的bi;假设b数组里靠前的是比较大的数,挑过以后肯定还能保证后面较小的bi有数和它搭配,所以贪心是正确的。

Codeforces 1315C Restoring Permutation的更多相关文章

  1. [Codeforces 1208D]Restore Permutation (树状数组)

    [Codeforces 1208D]Restore Permutation (树状数组) 题面 有一个长度为n的排列a.对于每个元素i,\(s_i\)表示\(\sum_{j=1,a_j<a_i} ...

  2. CodeForces 483C Diverse Permutation

    Diverse Permutation Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  3. codeforces 483C.Diverse Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/483/C 题目意思:给出 n 和 k,要求输出一个含有 n 个数的排列 p1, p2, ...,pn,使得 ...

  4. Codeforces 898F - Restoring the Expression(字符串hash)

    898F - Restoring the Expression 思路:字符串hash,base是10,事实证明对2e64取模会T(也许ull很费时),对1e9+7取模. 代码: #include< ...

  5. Codeforces 285C - Building Permutation

    285C - Building Permutation 思路:贪心.因为每个数都不同且不超过n,而且长度也为n,所有排列只能为1 2 3 ......n.所以排好序后与对应元素的差值的绝对值加起来就是 ...

  6. codeforces C. Diverse Permutation

    C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. CodeForces - 233A Perfect Permutation

    A. Perfect Permutation time limit per test: 2 seconds memory limit per test: 256 megabytes input: st ...

  8. Codeforces 863F - Almost Permutation

    863F - Almost Permutation 题意 给出每个位置可以放的数字的范围,定义 \(cost = \sum_{i=1}^{n}(cnt(i))^2\) ,其中 \(cnt(i)\) 为 ...

  9. Codeforces 932.C Permutation Cycle

    C. Permutation Cycle time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

随机推荐

  1. If no other git process is currently running, this probably means a git proc

    原因:用SourceTree提交代码,发现这个问题.好像是因为上个进程没停止,造成文件不识别 解决:把仓库目录里的.git/index.lock文件(文件是隐藏的)删除就可以了.删除index.loc ...

  2. Selenium chromeDriver启动时报错:session not created: This version of ChromeDriver only supports Chrome

    解决方案: 这是因为ChromeDriver与本地chrome浏览器的版本不一致导致 ChromeDriver下载地址:http://npm.taobao.org/mirrors/chromedriv ...

  3. Android_ViewPager+Fragment实现页面滑动和底部导航栏

    1.Xml中底部导航栏由一个RadioGroup组成,其上是ViewPager. <?xml version="1.0" encoding="utf-8" ...

  4. Linux C++ 直接选择排序,冒泡排序,快速排序

    选择排序的思想是:每次从待排序中选择最小(大)的元素插入已经排好的序列中. /*直接选择排序*/ #include <iostream> using namespace std; void ...

  5. 到头来还是逃不开Java - Java13核心类

    Java13核心类 没有特殊说明,我的所有学习笔记都是从廖老师那里摘抄过来的,侵删 引言 兜兜转转到了大四,学过了C,C++,C#,Java,Python,学一门丢一门,到了最后还是要把Java捡起来 ...

  6. Qt程序异常结束,The process was ended forcefully....

    我用的Qt版本是5.9.6,运行了好几次程序都妥妥当当的,然后就被安排上了...出现如下错误: 也是刚入手Qt不久,出现这样的错误我以为是代码的问题,然后撤销一些代码发现还是这样的错,索性就关闭Qt然 ...

  7. Ehcache缓存框架与 Shiro 框架 出现出现验证错误 && Tomcat 缓存清除的问题

    当一个项目使用久了以后就会出现各种问题,下面是我遇到的一个权限验证错误的问题 我的项目是   Ehcache 结合 Shiro  一起使用的,项目用用久了出现   Token验证错误,Cookie之类 ...

  8. cpu几核

    import psutil def GetCpuInfo(): cpu_count = psutil.cpu_count(logical=False) #1代表单核CPU,2代表双核CPU xc_co ...

  9. 题解【洛谷P1433】吃奶酪

    题面 看到数据范围那么小,一眼状压\(\text{DP}\). 设\(dp[i][s]\)表示从\(i\)出发,走过的点的集合为\(s\)的最小距离. 不难推出转移方程(\(dis(i,j)\)为\( ...

  10. thinkphp 二级域名绑定模块,导致设置的路由被多域名共用的问题解决方案

    问题背景: 在router.php路由配置文件设置了二级域名和路由设置 use think\Route; Route::domain('www','index'); Route::domain('ad ...