I am trying to solve this problem. But I am getting a ‘fatal’ error. I am not able to find the reason of the error as I think this code works fine. Please help me find why this produces a ‘fatal’ error. Here, you can see the submission queue. I continuously got three 'fatal’s. Also, if you just look at the list, you’ll see so many fatals, I think that I am missing something.

Here’s my code:

```
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int maximum, j, new_index, temp;
vector<int> array;
array.resize(n);
for (int c = 0; c < k; c++) {
bool last = true;
for (int index = 0; index < n; index++) {
cin >> array[index];
if (last && array[index] != n - index) {
last = false;
}
}
if (last) {
for (int index = 0; index < n; index++) {
cout << index + 1 << " ";
}
cout << endl;
continue;
}
maximum = array[n-1];
j = n-2;
while (array[j] > maximum) {
maximum = array[j];
j--;
}
new_index = j + 1;
for (int index = j + 1; index < n; index++) {
if ((array[new_index] > array[index]) && (array[index] > array[j])) {
new_index = index;
}
}
temp = array[j];
array[j] = array[new_index];
array[new_index] = temp;
sort(array.begin() + j + 1, array.end());
for (int index = 0; index < n; index++) {
cout << array[index] << " ";
}
cout << endl;
}
return 0;
}
```