func_code_string: #include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int N = 1005;   int n, m;   int a[N], ans[N], pre[N];   int main() {     int i, j, k, t, nc = 0;     while (scanf( %d%d , &n, &m) != EOF) {       int tmin = -1, tpre = -1;       for (i = 1; i <= m; i++) {         scanf( %d , &a[i]);         if (tmin < a[i]) {           k = i;           tmin = a[i];         }       }       bool work = true;       ans[1] = k;       a[k]--;       for (i = 1; i <= m; i++) pre[i] = N;       pre[k] = 1;       for (i = 2; i < n; i++) {         tmin = -1;         for (j = 1; j <= m; j++) {           if (a[j] == 0 || j == ans[i - 1]) continue;           if (tmin < a[j] || tmin == a[j] && pre[j] < tpre) {             k = j;             tmin = a[j];             tpre = pre[j];           }         }         if (tmin == N) break;         ans[i] = k;         a[k]--;         pre[k] = i;       }       if (i < n)         work = false;       else {         for (i = 1; i <= m; i++) {           if (a[i] > 0 && i != ans[1] && i != ans[n - 1]) {             ans[n] = i;             break;           }         }         if (i > m) work = false;       }       if (!work)         printf( -1 n );       else {         for (i = 1; i <= n; i++) {           printf( %d , ans[i]);           if (i < n)             printf(   );           else             printf(  n );         }       }     }     return 0;   }   