Coffee Break(贪心+STL)

Recently Monocarp got a job. His working day lasts exactly mm minutes. During work, Monocarp wants to drink coffee at certain moments: there are nn minutes a1,a2,…,ana1,a2,…,an , when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute).

However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute aiai , Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least dd minutes pass between any two coffee breaks. Monocarp also wants to take these nn coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than dd minutes pass between the end of any working day and the start of the following working day.

For each of the nn given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.

Input

The first line contains three integers nn , mm , dd (1≤n≤2⋅105,n≤m≤109,1≤d≤m)(1≤n≤2⋅105,n≤m≤109,1≤d≤m)  — the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks.

The second line contains nn distinct integers a1,a2,…,ana1,a2,…,an (1≤ai≤m)(1≤ai≤m) , where aiai is some minute when Monocarp wants to have a coffee break.

Output

In the first line, write the minimum number of days required to make a coffee break in each of the nn given minutes.

In the second line, print nn space separated integers. The ii -th of integers should be the index of the day during which Monocarp should have a coffee break at minute aiai . Days are numbered from 11 . If there are multiple optimal solutions, you may print any of them.

Examples

Input

4 5 3
3 5 1 2

Output

3
3 1 1 2 

Input

10 10 1
10 5 7 4 6 3 2 1 9 8

Output

2
2 1 1 2 2 1 2 1 1 2 

Note

In the first example, Monocarp can take two coffee breaks during the first day (during minutes 11 and 55 , 33 minutes will pass between these breaks). One break during the second day (at minute 22 ), and one break during the third day (at minute 33 ).

In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.

题目大意:有一位员工想要利用喝咖啡来休息,他给了一个数组表示他想要喝咖啡的时间点(假设他喝咖啡用时1分钟),老板规定每次喝咖啡的时间间隔必须要大于d。问:他将给定数组的时间点都过一遍历一遍最少(贪心所在)需要多长时间,并输出每个时间点是在第几天经历的;

 

解题思路:贪心地选取喝咖啡的时间,我们尽量选取喝咖啡时间靠前的,然后贪心寻找能放在他后面最靠前的时间点,如果放不开就新开一天。

用map+queue

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include<algorithm>
#include<iomanip>
#define SIS std::ios::sync_with_stdio(false)
#define ll long long
#define INF 0x3f3f3f3f
#define mod 998244353
const int MAXN = 1e9 + 7;
const double PI = 3.14159265358979;
using namespace std;
const int N = 1e6 + 5;
/*int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
ll _power(int a, int b)//计算a^b;
{
	int ans=1, res=a;
	while(b){
		if(b&1) ans=ans*res%mod;
		res=res*res%mod;
		b>>=1;
	}
	return ans%mod;
	*/
queue<int> q;
map<int, int> ma;
int a[N], same[N];
int main() {
	int n, m, d;
	int sign = 1;
	SIS;
	cin >> n >> m >> d;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		same[i] = a[i];
	}
	
	sort(same+1, same + n+1);
	ma[same[1]] = 1;
	q.push(1);
	for (int i = 2; i <= n; i++) {
		int top = q.front();
		if (same[i] - same[top] > d) {
			ma[same[i]] = ma[same[top]];
			q.pop();
		}
		else {
			sign++;
			ma[same[i]] = sign;
		}
		q.push(i);
	}
	cout << sign << endl;
	for (int i = 1; i <= n; i++) {
		if (i == 1) cout << ma[a[i]];
		else
			cout << " " << ma[a[i]];
	}
	cout << endl;
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

deebcjrb

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值