/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left224
#define right right224
#define next next224
#define rank rank224
#define prev prev224
#define y1 y1224
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define mp make_pair
const string FILENAME = "input";
const int MAXN = 100228;
int n, d, m;
int cnt[MAXN];
vector<int> who[MAXN];
bool check(int x) {
queue<int> kek;
for (int i = 0; i < n; i++) {
for (int j = 0; j < cnt[i]; j++) {
kek.push(i);
}
for (int k = 0; k < x; k++) {
if (kek.empty()) {
break;
}
int a = kek.front();
kek.pop();
if (i - a > d) {
return false;
}
}
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//read(FILENAME);
cin >> n >> d >> m;
for (int i = 0; i < m; i++) {
int g;
cin >> g;
g--;
cnt[g]++;
who[g].pb(i);
}
int l = 1;
int r = m;
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid)) {
r = mid;
} else {
l = mid + 1;
}
}
cout << l << endl;
queue<int> kek;
for (int i = 0; i < n; i++) {
for (int j = 0; j < cnt[i]; j++) {
kek.push(who[i][j]);
}
for (int k = 0; k < l; k++) {
if (kek.empty()) {
break;
}
int a = kek.front();
kek.pop();
cout << a + 1 << ' ';
}
cout << 0 << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
4468 KB |
Output is correct |
2 |
Correct |
39 ms |
4376 KB |
Output is correct |
3 |
Correct |
35 ms |
4468 KB |
Output is correct |
4 |
Correct |
35 ms |
4468 KB |
Output is correct |
5 |
Correct |
35 ms |
4560 KB |
Output is correct |
6 |
Correct |
36 ms |
4468 KB |
Output is correct |
7 |
Correct |
35 ms |
4468 KB |
Output is correct |
8 |
Correct |
35 ms |
4432 KB |
Output is correct |
9 |
Correct |
41 ms |
4380 KB |
Output is correct |
10 |
Correct |
43 ms |
4344 KB |
Output is correct |
11 |
Correct |
35 ms |
4276 KB |
Output is correct |
12 |
Correct |
66 ms |
5880 KB |
Output is correct |
13 |
Correct |
97 ms |
8024 KB |
Output is correct |
14 |
Correct |
151 ms |
10132 KB |
Output is correct |
15 |
Correct |
156 ms |
11000 KB |
Output is correct |
16 |
Correct |
214 ms |
13688 KB |
Output is correct |
17 |
Correct |
255 ms |
16064 KB |
Output is correct |
18 |
Correct |
257 ms |
15688 KB |
Output is correct |
19 |
Correct |
304 ms |
16872 KB |
Output is correct |
20 |
Correct |
255 ms |
16248 KB |
Output is correct |