CF1041C.Coffee Break

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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,…,ana_1, a_2, \dots, a_n, 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 aia_i, 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.

最近,Monocarp 找到了一份工作。他的每个工作日恰好持续 mm 分钟。在工作期间,Monocarp 希望在某些特定时刻喝咖啡:共有 nn 个时间点 a1,a2,…,ana_1, a_2, \dots, a_n,他在这些分钟内有能力且愿意喝一杯咖啡(为简化起见,我们假设每次咖啡休息恰好持续一分钟)。

然而,Monocarp 的老板不喜欢他过于频繁地喝咖啡。因此,对于计划在第 aia_i 分钟进行的这次咖啡休息,Monocarp 必须选择一个工作日,在该日的这一分钟喝咖啡,使得同一天内任意两次咖啡休息之间至少间隔 dd 分钟。Monocarp 还希望在尽可能少的工作日内完成这 nn 次咖啡休息(他不计入未上班的日子,也不在那些日子里喝咖啡)。请注意:任意两个连续工作日之间,从上一日结束到下一日开始的时间间隔严格大于 dd 分钟。

对给定的 nn 个分钟中的每一个,请确定 Monocarp 应在哪一天(即第几天)于该分钟喝咖啡。你必须使所用工作日总数最小。

输入格式

The first line contains three integers nn, mm, dd (1≤n≤2⋅105,n≤m≤109,1≤d≤m)(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le 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,…,ana_1, a_2, \dots, a_n (1≤ai≤m)(1 \le a_i \le m), where aia_i is some minute when Monocarp wants to have a coffee break.

第一行包含三个整数 nn、mm、dd (1≤n≤2⋅105, n≤m≤109, 1≤d≤m)(1 \le n \le 2\cdot10^{5},\ n \le m \le 10^{9},\ 1 \le d \le m) —— 分别表示 Monocarp 想要进行的咖啡休息次数、每天工作时长(单位:分钟)以及任意两次连续咖啡休息之间所需的最短时间间隔(单位:分钟)。

第二行包含 nn 个互不相同的整数 a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤m)(1 \le a_i \le m),其中 aia_i 表示 Monocarp 希望进行咖啡休息的某一分钟时刻。

输出格式

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 aia_i. Days are numbered from 11. If there are multiple optimal solutions, you may print any of them.

第一行输出在给定的 nn 个时刻中,每个时刻都安排一次咖啡休息所需的最少天数。

第二行输出 nn 个用空格分隔的整数。其中第 ii 个整数表示 Monocarp 应在第几天的第 aia_i 分钟进行咖啡休息。天数从 11 开始编号。若存在多个最优解,输出任意一个即可。

输入输出样例

  • 输入#1

    4 5 3
    3 5 1 2

    输出#1

    3
    3 1 1 2
  • 输入#2

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

    输出#2

    2
    2 1 1 2 2 1 2 1 1 2

说明/提示

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.

在第一个例子中,Monocarp 可以在第一天安排两次咖啡休息(分别在第 11 分钟和第 55 分钟,两次休息之间间隔 33 分钟),第二天安排一次咖啡休息(在第 22 分钟),第三天安排一次咖啡休息(在第 33 分钟)。

在第二个例子中,Monocarp 可以按如下方式确定每次休息所在的日期:若他想休息的时刻(分钟数)为奇数,则该次休息安排在第一天;若为偶数,则安排在第二天。

输入解题思路,AI测评打分。不知道怎么写?

首页