#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define oopt cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false);
#define forn(i,n) for(int i = 0; i<n; i++)
#define sz(x) (x).size()
using namespace std;
int main() {
//oopt;
int n,d,m; cin >> n >> d>>m;
vi naroceni(n);
vector<vector<int>> vrednosti(n); // to ti poje malo preveč vsega (že prazen deque = 80 bytov)
pair<int,int> pntr = {0,0}; //na katerem id-ju smo, pa kateri po vrsti tam
forn(i,m){
int t; cin >> t; naroceni[--t]++;
vrednosti[t].push_back(i+1);
}
int l = 1, r= m;
while(l<r){
int rob = (l+r)/2;
pntr = {0,0};
bool vredu = true;
forn(i,n){
if(!vredu) break;
int mesta = rob;
while(mesta){
while(pntr.first <= i && pntr.second >= vrednosti[pntr.first].size()){
if(i - pntr.first > d){
vredu = false;
break;
}
pntr.first++;
pntr.second = 0;
}
if(!vredu || pntr.first > i) break;
pntr.second++;
mesta--;
}
}
if(pntr.first < n && n - pntr.first > d)
vredu = false;
if(vredu){
r = rob;
} else {
l = rob+1;
}
}
cout << l << "\n";
pntr = {0,0};
forn(i,n){
int mesta = l;
while(mesta){
while(pntr.first <= i && pntr.second >= vrednosti[pntr.first].size()){
pntr.first++;
pntr.second = 0;
if(pntr.first > i || pntr.first >= n) break;
}
if(pntr.first > i || pntr.first >= n) break;
cout << vrednosti[pntr.first][pntr.second] << " ";
pntr.second++;
mesta--;
}
cout << "0\n";
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |