#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int a = 0, b = 0, c = 0;
vector<int> m;
bool check(vector<int> x, int num1) {
sort(x.begin(), x.end());
for (int i = 0; i < c; i++) {
x[i] += b;
}
for (int i = 0; i < c; i++) {
x[i] -= (i + num1) / num1;
if (i == c - 1 && (i + num1) / num1 > a) {
return false;
}
}
for (int i = 0; i < c; i++) {
if (x[i] < 0) {
return false;
}
}
return true;
}
int sortAndFind(int o) {
for (int i = 0; i < c; i++) {
if (o == m[i]) {
m[i] = -1;
return m[i];
}
}
return 0;
}
int main() {
int in1, in2, in3;
cin >> in1 >> in2 >> in3;
m.resize(in3);
for (int i = 0; i < in3; i++) {
cin >> m[i];
}
vector<int> m1 = m;
sort(m1.begin(), m1.end());
a = in1;
b = in2;
c = in3;
vector<int> m3(in3);
for (int i = 0; i < in3; i++) {
m3[i] = sortAndFind(m1[i]);
}
int l = 0, r = in3 - 1;
while (l < r) {
int mid = (l + r) / 2;
if (!check(m, mid)) {
l = mid + 1;
} else {
r = mid;
}
}
cout << l << endl;
for (int j = 0; j < in1; j++) {
for (int i = 0; i < l; i++) {
if ((i + l * j) < m3.size()) {
cout << m3[i + l * j] << " ";
}
}
cout << 0 << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |