Coffee Break Gym - 101911A

2023-11-09 16:11
文章标签 gym break coffee 101911a

本文主要是介绍Coffee Break Gym - 101911A,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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.

#include <bits/stdc++.h>using namespace std;
typedef long long ll;
set<int> s;
map<int,int> mp;
int a[200005];
int ans[200005];
int main()
{int n,m,i,j,k,d,x;scanf("%d%d%d",&n,&m,&d);for(i=1;i<=n;i++){scanf("%d",&a[i]);s.insert(a[i]);mp[a[i]] = i;}set<int>::iterator it;int day = 1;while(s.size() != 0){for(i=1;;){it = s.lower_bound(i);if(it==s.end()){day++;break;}else{ans[mp[*it]] = day;s.erase(*it);i = *it+ d + 1;}}}printf("%d\n",day-1);for(i=1;i<=n;i++){if(i != 1) printf(" ");printf("%d",ans[i]);}printf("\n");return 0;
}

 

这篇关于Coffee Break Gym - 101911A的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/377185

相关文章

javascript中break与continue的区别

在javascript中,break是结束整个循环,break下面的语句不再执行了 for(let i=1;i<=5;i++){if(i===3){break}document.write(i) } 上面的代码中,当i=1时,执行打印输出语句,当i=2时,执行打印输出语句,当i=3时,遇到break了,整个循环就结束了。 执行结果是12 continue语句是停止当前循环,返回从头开始。

Go 语言中Select与for结合使用break

func test(){i := 0for {select {case <-time.After(time.Second * time.Duration(2)):i++if i == 5{fmt.Println("break now")break }fmt.Println("inside the select: ")}fmt.Println("inside the for: ")}} 执行后

switch中的break控制

#include<iostream>using namespace std;int main(){int i=10;switch(i){case 9:i+=1;case 10:i+=1;case 11:i+=1;default:i+=1;}cout<<i<<endl;return 0;} 上面的结果是13; #include<iostream>using namespace s

Java中break和continue的区别?

for(int i=0;i<5;i++){ if(i==3) { continue; //继续循环 //break; //中断循环 } System.out.println(i); } 以上输出0 1 2 4 如果换成break,输出0 1 2

Creating OpenAI Gym Environment from Map Data

题意:从地图数据创建 OpenAI Gym 环境 问题背景: I am just starting out with reinforcement learning and trying to create a custom environment with OpenAI gym. However, I am stumped with trying to create an enviro

java复习第九课,break和continue语句

break:终止整个循环。在任何循环语句的主题部分,均可用break控制循环流程。break用于强行推出循环,不执行循环剩下的语句。 比如:当我循环打印1到10的数字,在数字8后加break,遇到break语句后,强行跳出循环体,不在往下执行。 continue:终止当次循环,执行下一次。语句用在循环语句体重,用于终止某次循环过程,即跳过循环体中尚未执行的语句,接着进行下一次是否执行循环

【codeforces】gym 101137 K - Knights of the Old Republic【用最小生成树对图做集合dp】

题目链接:【codeforces】gym 101137 K - Knights of the Old Republic 考虑对图集合dp,一个连通块的dp值为两个连通块的值的和或者强制加一条新边后的最小值,取个最小值(边从小到大枚举,则强制加一条最大的边会导致连通块内较小的边一定都选,则会构成一个生成树)。用kruskal实现这个dp过程即可。 #include <bits/stdc++.h>

【codeforces】gym 101138 K. The World of Trains【前缀和优化dp】

题目链接:K. The World of Trains 记录一个横着的前缀dp和以及斜着的前缀dp,复杂度 O(n2) O(n^2) #include <bits/stdc++.h>using namespace std ;typedef pair < int , int > pii ;typedef long long LL ;#define clr( a , x ) memset (

How to user “Discrete“ object in openai-gym environments?

题意:怎样在 OpenAI Gym 环境中使用 “Discrete” 对象 问题背景: I am trying to create a Q-Learning agent for a openai-gym "Blackjack-v0" environment. I am trying to get the size of the observation space but its in

Python控制流:循环控制(break, continue, pass)③

文章目录 前言1. 循环结构1.1 `for` 循环1.2 `while` 循环 2. 循环控制语句2.1 `break` 语句2.2 `continue` 语句2.3 `pass` 语句 3. 综合详细的例子:银行账户管理系统3.1 类和方法`BankAccount` 类 3.2 主函数 4. 循环控制语句的常见用法4.1 使用 `break` 终止无限循环4.2 使用 `continu