#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define coutpair(p) cout << p.first << " " << p.second << "|"
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll INF = 1e15;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, d, m; cin >> n >> d >> m;
pll jb[m];
for (int i=0; i<m; i++) cin >> jb[i].first, jb[i].second = i+1;
sort(jb, jb+m);
ll lo = 1, hi = 1e9, ans = INF;
deque<pll> dq;
while (lo <= hi){
ll x = (lo+hi)/2;
dq.clear();
for (int i=1; i<=n; i++) dq.push_back({i, x});
bool pos = true;
for (int i=0; i<m; i++){
ll tar = jb[i].first+d;
if (tar < dq.front().first || dq.empty()){
pos = false;
break;
}
while (jb[i].first > dq.front().first) dq.pop_front();
dq.front().second--;
if (dq.front().second == 0) dq.pop_front();
}
if (pos) hi = x-1, ans = min(ans, x);
else lo = x+1;
}
stack<pll> s;
for (int i=n; i>=1; i--) s.push({i, ans});
vector<ll> v[n+1];
for (int i=0; i<m; i++){
auto [day, id] = jb[i];
while (day > s.top().first) s.pop();
v[s.top().first].push_back(id); s.top().second--;
if (s.top().second == 0) s.pop();
}
cout << ans << "\n";
for (int i=1; i<=n; i++){
if (v[i].empty()) cout << 0 << "\n";
else{
for (auto it : v[i]) cout << it << " ";
cout << 0 << "\n";
}
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |