#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<int, int>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
#define t_test int t;cin >> t;while(t--)
const ll mod = 1e9 + 7;
const ll INF = 1e18;
inline void adm(ll &x){if(x>=mod)x%=mod;else if(x<0)x+=mod;}
//--------------------------------------------------------------------
int n, d, m;
const int N = 1e5 + 10;
int a[1000003];
int cnt[N];
vector<int> vt[N], ans[N];
bool check(int x) {
queue<pa> q;
FOR(i, 1, n) {
if(cnt[i] != 0)
q.push({i + d, cnt[i]});
if(q.size() == 0) continue;
int cur = x;
while(!q.empty()) {
int v = q.front().fi, sl = q.front().se;
q.pop();
if(v < i) return false;
if(cur - sl < 0) {
sl -= cur;
q.push({v, sl});
break;
}
cur -= sl;
}
}
return true;
}
void hbmt() {
cin >> n >> d >> m;
FOR(i, 1, m) {
cin >> a[i];
cnt[a[i]]++;
vt[a[i]].push_back(i);
}
int l = 1, r = m;
int res = 0;
while(l <= r) {
int mid = l + r >> 1;
if(check(mid)) {
r = mid - 1;
res = mid;
}
else l = mid + 1;
}
queue<pa> q;
FOR(i, 1, n) {
if(cnt[i] != 0)
q.push({i + d, cnt[i]});
if(q.size() == 0) continue;
int cur = res;
while(!q.empty()) {
int v = q.front().fi, sl = q.front().se;
q.pop();
if(cur - sl < 0) {
int x = cur;
while(!vt[v - d].empty() && x--) {
ans[i].push_back(vt[v - d].back());
vt[v - d].pop_back();
}
sl -= cur;
q.push({v, sl});
break;
}
int x = sl;
while(!vt[v - d].empty() && x--) {
ans[i].push_back(vt[v - d].back());
vt[v - d].pop_back();
}
cur -= sl;
}
}
cout << res << '\n';
FOR(i, 1, n) {
for(auto e : ans[i]) {
cout << e << ' ';
}
cout << 0 << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
if(fopen("hbmt.inp", "r")) {
freopen("hbmt.inp", "r", stdin);
freopen("hbmt.out", "w", stdout);
}
// t_test
hbmt();
return 0;
}
Compilation message (stderr)
jobs.cpp: In function 'int main()':
jobs.cpp:101:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
101 | freopen("hbmt.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:102:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
102 | freopen("hbmt.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |