Pagini recente » Cod sursa (job #1357291) | Cod sursa (job #2522204) | Cod sursa (job #1148277) | Cod sursa (job #1381316) | Cod sursa (job #2508437)
#include <fstream>
#include <algorithm>
ifstream cin("partitie.in");
ofstream cout("partitie.out");
using namespace std;
int p[300005], cap[300005];
struct poz{
int first;
int second;
};
poz v[300005];
bool cmp1(const poz &a, const poz &b)
{
return a.first < b.first;
}
bool cmp2(const poz &a, const poz &b)
{
return a.second < b.second;
}
int main()
{
int n, d, i, j, x, cnt=1, okn=0;
cin >> n >> d;
for (i=1; i<=n; i++)
{cin >> x;
v[i].first=x;
v[i].second=i;
}
sort(v+1, v+n+1, cmp1);
cout << endl;
p[v[1].second]=1;
cap[1]=v[1].first;
for (i=2; i<=n; i++)
{
okn=0;
for (j=1; j<=cnt; j++)
{
if (v[i].first>=cap[j]+d)
{
cap[j]=v[i].first;
p[v[i].second]=j;
okn=1;
break;
}
}
if (okn==0)
{
cnt++;
cap[cnt]=v[i].first;
p[v[i].second]=cnt;
}
}
sort (v+1, v+n+1, cmp2);
cout << cnt << '\n';
for (i=1; i<=n; i++)
cout << p[v[i].second] << '\n';
return 0;
}