Cod sursa(job #1787831)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 25 octombrie 2016 08:45:00
Problema Partitie Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <bits/stdc++.h>
using namespace std;

int main(){
	ifstream f("partitie.in");
	ofstream g("partitie.out");

	int n, d;
	f >> n >> d;

	set<pair<int, int>> s;
	for(int i = 0, x; i < n; ++i){
		f >> x;
		s.emplace(x, i); }

	vector<int> rez(n, 0);

	int i;
	for(i = 1; !s.empty(); ++i){
		auto cur = *begin(s);
		s.erase(begin(s));
		rez[cur.second] = i;
		while(true){
			auto it = s.lower_bound(make_pair(cur.first+d, 0));
			if(it == end(s)) break;
			cur = *it;
			s.erase(it);

			rez[cur.second] = i; } }
	
	g << i-1 << '\n';
	for(const auto x : rez){
		g << x << '\n'; }

	return 0; }