fork(2) download
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. int main() {
  9. int t,n;
  10. bool ny;
  11. bool c;
  12. int mark,i;
  13. int sum;
  14. int a[51];
  15. cin>>t;
  16. while(t--) {
  17. cin>>n;
  18. sum = 0;
  19. c = false;
  20. for(i = 0; i < n; i++) {
  21. cin>>a[i];
  22. if(a[i] == n)
  23. c = true;
  24. sum += a[i];
  25. }
  26. if(sum != n || c) {
  27. cout<<"-1"<<endl;
  28. continue;
  29. }
  30. mark = 1;
  31. for(int p = 0; p < n; p++) {
  32. ny = true;
  33. while(ny) {
  34. if(a[mark] > 0 && p != mark) {
  35. a[mark]--;
  36. cout<<mark+1<<" ";
  37. ny = false;
  38. }
  39. else {
  40. mark++;
  41. mark = mark % n;
  42. }
  43. }
  44. }
  45. cout<<endl;
  46. }
  47. return 0;
  48. }
Success #stdin #stdout 0s 2688KB
stdin
4
10
1 2 4 2 0 0 0 0 0 1
25
1 1 1 1 1 4 6 7 8 9 5 0 0 0 0 0 0 0 0 1 1 2 3 0 0 
25
1 1 1 1 1 4 6 7 0 0 0 0 0 0 0 0 0 0 0 1 0 2 0 0 0
7
3 2 1 0 0 0 1 
stdout
2 3 4 10 1 2 3 3 3 4 
-1
2 3 4 5 6 7 8 20 22 22 1 6 6 6 7 7 7 7 7 8 8 8 8 8 8 
2 3 7 1 1 1 2