#pragma GCC optimize("Ofast") #include #define LL long long int #define ULL unsigned LL #define LD long double #define FI first #define SE second #define PB push_back #define PF push_front #define V vector #define PQ priority_queue #define ALL(x) x.begin(), x.end() #define SZ(x) (int)(x).size() #define FORI(i, a, b) for(int i = a; i < b ; ++i) #define FORD(i, a, b) for(int i = a; i > b ; --i) using namespace std; using pii = pair; const int INF = 1e9; void fill(int segment, int& pos, int& val, int& jumps, int p, V& a){ FORI(_,0,segment){ a[pos++] = val--; if (val == 1){ val = p; jumps++; } } } int main(){ ifstream cin("notdecreasing.in"); ofstream cout("notdecreasing.out"); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); clock_t start_t = clock(); int n, p, l = 0; cin >> n >> p; V b(n), segs; bool imp = 0; FORI(r,0,n){ cin >> b[r]; if (r){ if (b[r-1] > b[r]){ imp = 1; break; } if (b[r-1] < b[r]){ segs.push_back(r - l + 1); l = r + 1; } } } imp |= b[n-1] == 0; if (imp){ cout << -1; return 0; } // for(auto seg: segs){ // cout << seg << ' '; // } int pos = 0, val = p, jumps = 0; V a(n); for(auto seg: segs){ fill(seg-1, pos, val, jumps, p, a); if (jumps-- == 0){ cout << -1; return 0; } a[pos++] = 1; } fill(n-pos, pos, val, jumps, p, a); l = 0; FORI(r,0,n){ if (a[r] == 1){ sort(a.begin()+l, a.begin()+r, greater()); l = r + 1; } } sort(a.begin()+l, a.end(), greater()); FORI(i,0,n){ cout << a[i] << ' '; } return 0; }