problem

C. Phoenix and Towers
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Phoenix has n blocks of height h1,h2,…,hn, and all hi don’t exceed some value x. He plans to stack all n blocks into m separate towers. The height of a tower is simply the sum of the heights of its blocks. For the towers to look beautiful, no two towers may have a height difference of strictly more than x.

Please help Phoenix build m towers that look beautiful. Each tower must have at least one block and all blocks must be used.

Input
The input consists of multiple test cases. The first line contains an integer t (1≤t≤1000) — the number of test cases.

The first line of each test case contains three integers n, m, and x (1≤m≤n≤105; 1≤x≤104) — the number of blocks, the number of towers to build, and the maximum acceptable height difference of any two towers, respectively.

The second line of each test case contains n space-separated integers (1≤hi≤x) — the heights of the blocks.

It is guaranteed that the sum of n over all the test cases will not exceed 105.

Output
For each test case, if Phoenix cannot build m towers that look beautiful, print NO. Otherwise, print YES, followed by n integers y1,y2,…,yn, where yi (1≤yi≤m) is the index of the tower that the i-th block is placed in.

If there are multiple solutions, print any of them.

Example
inputCopy
2
5 2 3
1 2 3 1 2
4 3 3
1 1 2 3
outputCopy
YES
1 1 1 2 2
YES
1 2 2 3
Note
In the first test case, the first tower has height 1+2+3=6 and the second tower has height 1+2=3. Their difference is 6−3=3 which doesn’t exceed x=3, so the towers are beautiful.

In the second test case, the first tower has height 1, the second tower has height 1+2=3, and the third tower has height 3. The maximum height difference of any two towers is 3−1=2 which doesn’t exceed x=3, so the towers are beautiful.

solution

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
struct node{int v, id; bool operator < (node b)const{return v>b.v;}
};
int h[maxn], cc[maxn];
int main(){int T;  cin>>T;while(T--){//memset(h,0,sizeof(h));int n, m, x;  cin>>n>>m>>x;priority_queue<node>q;for(int i = 1; i <= n; i++){int t;  cin>>t;  q.push({t,i});h[i] = 0;}int be = 1;while(q.size()){node t = q.top(); q.pop();h[be] += t.v;cc[t.id] = be;be++;if(be==m+1)be = 1;}int mx = 0, mi = 1e9+10;for(int i = 1; i <= m; i++){mx = max(mx, h[i]);mi = min(mi, h[i]);}if(mx-mi > x)cout<<"NO\n";else {cout<<"YES\n";for(int i = 1; i <= n; i++)cout<<cc[i]<<" ";cout<<"\n";}}return 0;
}

Codeforces Global Round 14, C. Phoenix and Towers相关推荐

  1. Codeforces Global Round 14 F. Phoenix and Earthquake 思维 + 并查集

    传送门 文章目录 题意: 思路: 题意: 给你nnn个点,mmm条边,限制xxx,每个点都有沥青aia_iai​,定义合并两个点即两点之间有边且au+av≥xa_u+a_v\ge xau​+av​≥x ...

  2. Codeforces Global Round 14 E. Phoenix and Computers 思维 + dp

    传送门 文章目录 题意: 思路: 题意: 有nnn台电脑,你可以手动打开某个电脑,如果第i−1,i+1i-1,i+1i−1,i+1台电脑都打开了,那么第iii台电脑会自动打开.不能手动打开自动打开的电 ...

  3. Codeforces Global Round 14 E Phoenix and Computers

    大意: 一排电脑,每次可以选择打开一台电脑,如果某一台电脑相邻的左边和右边都被打开了,它会自动打开.问打开n台电脑的方案数 思路: O(n^3)做法 不难发现,在操作过程中,一台台电脑其实就是被分成了 ...

  4. Codeforces Global Round 1 晕阙记

    Codeforces Global Round 1 晕阙记 我做这场比赛的时候晕得要死.做这三道题做太久了,rating涨不起来啊! A 如果愿意的话你可以看做是膜2意义下的运算,写快速幂等各种膜运算 ...

  5. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  6. Codeforces Global Round 1

    Codeforces Global Round 1 题解:The Editorial of the First Codeforces Global Round A:其实mod 2计算一下就行了 B:删 ...

  7. 【Codeforces Global Round 23】B. Rebellion

    Codeforces Global Round 23中B. Rebellion Codeforces比赛记录 文章目录 题目链接: 一.B. Rebellion 题目意思: 上思路: 总结 B. Re ...

  8. Codeforces Global Round 4-D. Prime Graph(伯特兰-切比雪夫定理)

    题目:Codeforces Global Round 4-D. Prime Graph 题意:给出n(顶点的个数),要求所得图满足: 1.无平行边和自环 2.边的总数是个质数 3.每个点的度(也就是点 ...

  9. codeforces global round 23

    constest :codeforces global round 23 contest time:2022.10.16 contest grade: 2800 contest rating chan ...

最新文章

  1. [笔记]C#基础入门(八)——C#标识符的命名规则
  2. 动态滴定预测算法研究
  3. OpenBFDD的安装与使用
  4. Oracle inline view 简介
  5. 深度学习方法笔记之(一):SVM的基本模型
  6. 2019阿里云618大促主会场全攻略
  7. php如何强制下载文件,php 强制下载文件实例代码
  8. StegaStamp:加州大学伯克利分校开源神奇的照片隐写术,打印的照片能当二维码用...
  9. 借助xUnit减少了生产问题
  10. Makefile--伪目标 (三)
  11. Maven的下载安装和环境配置
  12. 设置FlashBuilder4.7打开时选择项目(显示选择项目对话框)
  13. 使用Github上传本地项目代码
  14. python语句分号_Python中的分号
  15. php实现飘窗,装配式飘窗的制作方法
  16. Texi2Html中文输出版
  17. LaTex粗略的学习笔记(表格)
  18. 在Textview中获取指定文字位置(兼顾网址链接和emoji表情),并在其附近展示图片
  19. phpcms上传图片去除水印
  20. 原生Android设置sim卡锁定,开启SIM卡密码保护

热门文章

  1. 康德的道德观与哲学观
  2. Matlab Tricks(十五) —— 圆的正确画法
  3. 概率论(基本概念术语)的理解
  4. Trick(九)—— ++i 与 i++ 的本质区别
  5. 机器学习模型的理解(三)
  6. fire.php,php代码调试利器firephp安装与使用方法分析
  7. python是什么-什么是Python?最全的python百科
  8. 用python画八卦图-使用turtle绘制太极八卦图
  9. 爬虫python能做什么-Python除了爬虫,还能干啥?
  10. 简单python脚本实例-python常用运维脚本实例