#C982. Task Distribution
Task Distribution
Task Distribution
You are given a set of tasks and a limited number of days. Each task has an associated processing time. Your goal is to assign each task to one of the available days so that the maximum total processing time on any single day is minimized. For each test case, if a valid assignment is found, output "YES" followed by a list of day assignments for the tasks in their original order. Otherwise, output "NO".
The problem can be approached by performing a binary search on the possible maximum daily load and using a greedy algorithm to check if the tasks can be assigned under that limit. All formulas and mathematical expressions are given in LaTeX format. For example, the lower bound for the maximum daily load is (\max_{i} (a_i)) and the upper bound is (\sum_{i=1}^{n} a_i), where (a_i) represents the processing time of the (i)th task.
inputFormat
Input is read from standard input (stdin). The first line contains an integer (T) denoting the number of test cases. For each test case, the first line contains two integers (n) and (d), where (n) is the number of tasks and (d) is the number of days. The next line contains (n) integers representing the processing times of tasks.
outputFormat
For each test case, print two lines to standard output (stdout). The first line should be either "YES" if a valid assignment exists or "NO". If the answer is "YES", the second line should contain (n) integers where the (i)th integer represents the day number (from 1 to (d)) assigned to the (i)th task (in the original input order).## sample
2
5 3
4 2 6 3 5
6 2
1 3 2 6 5 4
YES
3 2 1 3 2
YES
2 2 2 1 1 2
</p>