C. Restoring Permutation

194 篇文章 1 订阅
71 篇文章 0 订阅

链接: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;
		}
		 
	}
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当程序在加载检查点时失败并出现"failed to load checkpoint, restoring previous"的错误信息时,意味着程序无法成功加载检查点,并正在恢复到先前保存的状态。 检查点是在机器学习或深度学习训练过程中定期保存的模型的快照。它通常用于在训练过程中定期保存模型的参数和优化器的状态,以便在需要时恢复训练过程。 "failed to load checkpoint"的错误信息表示加载检查点时出现了问题,可能是由于以下原因之一: 1. 检查点文件丢失或损坏:如果检查点文件在加载过程中丢失或损坏,程序将无法成功加载检查点。 2. 版本不兼容:如果使用的程序或库的版本与保存检查点时的版本不兼容,也可能导致加载失败。 在出现这个错误时,程序会尝试从先前保存的状态中进行恢复,这是为了最大限度地减少训练过程中的数据丢失。 为了解决这个问题,可以尝试以下步骤: 1. 检查检查点文件:确保检查点文件存在并且完好无损。如果文件丢失或损坏,你可能需要寻找其他备份或重新训练模型。 2. 检查版本兼容性:确保使用的程序和库的版本与保存检查点时的版本相匹配。如果版本不兼容,可以尝试更新程序或库,或者重新保存检查点。 最后,如果以上步骤都没有解决问题,你可能需要查找相关的错误消息和日志来获取更多的信息,或者在相关的社区或论坛上寻求帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值