Pagini recente » Cod sursa (job #734350) | Cod sursa (job #153688) | Cod sursa (job #1637988) | Cod sursa (job #433352) | Cod sursa (job #1627272)
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <queue>
using namespace std;
const int nmax= 300000;
struct str {
int x, y;
};
struct str_cmp {
bool operator () ( const str &x, const str &y ) {
return x.x>y.x;
}
};
str x[nmax+1];
priority_queue <str, vector <str>, str_cmp> last;
bool cmp1( str x, str y ) {
return x.x<y.x;
}
bool cmp2( str x, str y ) {
return x.y<y.y;
}
inline str mp( int x, int y ) {
str sol;
sol.x= x, sol.y= y;
return sol;
}
int main( ) {
assert( freopen( "partitie.in", "r", stdin ) ) ;
assert( freopen( "partitie.out", "w", stdout ) ) ;
int n, d;
assert( scanf( "%d%d", &n, &d ) ) ;
for ( int i= 1; i<=n; ++i ) {
assert( scanf( "%d", &x[i].x ) ) ;
x[i].y= i;
}
sort( x+1, x+n+1, cmp1 ) ;
int k= 0;
for ( int i= 1; i<=n; ++i ) {
if ( !last.empty() ) {
str nr= last.top();
if ( nr.x+d<=x[i].x ) {
last.pop();
nr.x= x[i].x;
x[i].x= nr.y;
last.push(nr);
continue;
}
}
++k;
last.push(mp(x[i].x, k));
x[i].x= k;
}
sort( x+1, x+n+1, cmp2 ) ;
printf("%d\n", k);
for ( int i= 1; i<=n; ++i ) {
printf("%d\n", x[i].x);
}
return 0;
}