解
模拟题,根据题意来,最好自己造几组测试数据。
先遍历有没有一组座位可以直接满足,没有就从头开始,不考虑连座把空余的座位直接分配(每一组都要分当前剩余座位大于等于和小于需求座位来处理)。
//
// Created by 29273 on 2021-04-05.
//
#include "bits/stdc++.h"
using namespace std;
int res[21];
int main() {
int n, a;
for (int i = 0; i < 22; ++i) {
res[i] = 5;
}
cin >> n;
for (int i = 0; i < n; ++i) {
int j;
cin >> a;
for (j = 0; j < 20; ++j) {
if (res[j] >= a) {
break;
}
}
if (j == 20) {
for (int k = 0; k < 20 && a > 0; ++k) {
if (res[k] > 0) {
if (res[k] >= a) {
for (int k1 = 0; k1 < a; ++k1) {
printf("%d ", k * 5 + 6 - res[k] + k1);
}
res[k] -= a;
} else {
for (int e = 0; e < res[k]; ++e) {
printf("%d ", k * 5 + 6 - res[k] + e);
}
a -= res[k];
res[k] = 0;
};
}
}
} else {
for (int k = 0; k < a; ++k) {
printf("%d ", j * 5 + 6 - res[j] + k);
}
res[j] -= a;
}
printf("\n");
}
return 0;
}