#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
int n;
int c[100005];
int a[100005];
int tot;
priority_queue<pair<int,int> > q;
void work(){
	tot=0;
	while(!q.empty()) q.pop();
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		if(c[i]>0) q.push({c[i],i});
	}
	while(!q.empty()){
		int now=q.top().second;
		q.pop();
		if(a[tot]!=now){
			a[++tot]=now;
			c[now]--;
			if(c[now]>0) q.push({c[now],now});
		}
		else if(!q.empty()){
			int nxt=q.top().second;
			q.pop();
			a[++tot]=nxt;
			c[nxt]--;
			if(c[nxt]>0) q.push({c[nxt],nxt});
			q.push({c[now],now});
		}
		else{
			cout<<-1<<'\n';
			return;
		}
	}
	for(int i=1;i<=tot;i++) cout<<a[i]<<" ";
	cout<<'\n';
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>t;
	while(t--) work();
    return 0;
}

4 条评论

  • 1

信息

ID
20037
时间
ms
内存
MiB
难度
显示难度暂无评定
标签
递交数
40
已通过
5
上传者