F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

排列

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 33    Accepted Submission(s): 13


Problem Description
给定正整数$n,m,b_1,b_2,...,b_m$,你需要构造一个$1$~$n$的排列。

满足将排列从前向后依次划分成$m$段后,第$i$段中有$b_i$个数,每一段中所有数的$gcd$都为$1$

保证$\sum_{i=1}^{m} b_i =n$

若有多种方案,输出字典序最小的;若无解输出$-1$
 

Input
多组数据

第一行一个正整数$T$代表询问组数

对于每组询问:

第一行两个整数$n,m$

第二行$m$个整数代表$b_i$

$1\le T,n,m,b_i \le 10^5$

保证$\sum n \le 10^6$
 

Output
对于每组询问:

若有解,输出一行$n$个数代表构造的排列;若无解输出$-1$
 

Sample Input
2 3 1 3 3 2 1 2
 

Sample Output
1 2 3 1 2 3
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-23 00:19:11, Gzip enabled