- 间隔摆放
为何85pts
- @ 2026-10-11 19:45:48
#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 条评论
-
33DAI 33 LV 10 (1/1) SU @ 2026-10-12 17:05:45
2 4 1 3 1 0 2 0 52 1 2 3 2 -1 -
@ 2026-10-12 17:02:02
2 4 0 0 0 0 3 0 0 0-1 -1 -
@ 2026-10-12 16:59:17+1
你是不是跟我一样PE了
我也查不出来
-
@ 2026-10-11 19:53:14??
- 1
信息
- ID
- 20037
- 时间
- ms
- 内存
- MiB
- 难度
- 显示难度暂无评定
- 标签
- 递交数
- 40
- 已通过
- 5
- 上传者