A workshop has n parts, each with a positive integer load, and k benches. The foreman wants to distribute every part to some bench so that each of the k benches ends up with exactly the same total load, and every bench receives at least one part.
Determine whether such a distribution is possible.
Line 1: two integers n and k.
Line 2: n space-separated positive integers, the part loads.
Print YES if the parts can be split into k equal-load groups, otherwise NO.
Example 1
Input
4 2 3 3 2 2
Expected
YES
Explanation
Total is 10, so each of the 2 benches needs load 5: {3,2} and {3,2}. Feasible, so YES.
Example 2
Input
4 2 1 1 1 5
Expected
NO
Explanation
Total is 8, so each bench needs load 4, but the load 5 cannot fit anywhere, so NO.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →