308414: CF1515C. Phoenix and Towers
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Phoenix and Towers
题意翻译
## 题目描述 凤凰菲克斯有 $ n $ 个方块,分别高 $ h_1,h2,\dots,h_n $,所有 $ h_i $ 都不超过 $ x $ 。他计划将 $ n $ 个方块堆叠成 $ m $ 座塔。为了让塔看起来更漂亮,没有两座塔的高度差可以超过 $ x $ 。 请帮助菲克斯建造 $ m $ 座漂亮的塔,每个塔必须至少由一个方块构成,并且必须使用所有方块。 ## 输入格式 有多组数据。 第一行输入一个正整数 $ T $($ 1 \le T \le 1000 $ ),表示数据的组数。 对于每组数据: 第一行输入三个正整数:$ n $ , $ m $ , $ x $ ( $ 1 \le m \le n \le 10^5 $ ; $ 1 \le x \le 10^4 $ ) 意义如题面中所述。分别是方块数、要建造的塔数和任意两个塔的最大可接受高度差。 第二行包含 $ n $ 个用空格分隔的整数($1\le h_i\le x$)表示块的高度。 保证所有测试用例的 $ n $ 总和不会超过 $ 10^5 $ 。 ## 输出格式 对于每组数据: 若菲克斯不能建造 $ m $ 座漂亮的塔,输出一个 "NO"。 否则,在第一行输出一个"YES"。后跟 $ n $ 个整数 $ y_1, y_2, \dots, y_n $ , 其中 $ y_i $ ($1\le y_i\le m$)表示 $ i $ 座塔的高度。 如果有多种解决方案,请输出其中任意一种。题目描述
Phoenix has $ n $ blocks of height $ h_1, h_2, \dots, h_n $ , and all $ h_i $ 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.输入输出格式
输入格式
The input consists of multiple test cases. The first line contains an integer $ t $ ( $ 1 \le t \le 1000 $ ) — the number of test cases. The first line of each test case contains three integers $ n $ , $ m $ , and $ x $ ( $ 1 \le m \le n \le 10^5 $ ; $ 1 \le x \le 10^4 $ ) — 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 \le h_i \le x $ ) — the heights of the blocks. It is guaranteed that the sum of $ n $ over all the test cases will not exceed $ 10^5 $ .
输出格式
For each test case, if Phoenix cannot build $ m $ towers that look beautiful, print NO. Otherwise, print YES, followed by $ n $ integers $ y_1, y_2, \dots, y_n $ , where $ y_i $ ( $ 1 \le y_i \le m $ ) is the index of the tower that the $ i $ -th block is placed in. If there are multiple solutions, print any of them.
输入输出样例
输入样例 #1
2
5 2 3
1 2 3 1 2
4 3 3
1 1 2 3
输出样例 #1
YES
1 1 1 2 2
YES
1 2 2 3