Pagini recente » Istoria paginii runda/shumenichb2013 | Cod sursa (job #2296641) | Cod sursa (job #684504) | Cod sursa (job #43993) | Cod sursa (job #1627261)
#include <algorithm>
#include <fstream>
#include <queue>
using namespace std;
ifstream fin("partitie.in");
ofstream fout("partitie.out");
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( ) {
int n, d;
fin>>n>>d;
for ( int i= 1; i<=n; ++i ) {
fin>>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 ) ;
fout<<k<<"\n";
for ( int i= 1; i<=n; ++i ) {
fout<<x[i].x<<"\n";
}
return 0;
}