#K76417. Balanced Team Formation

    ID: 34638 Type: Default 1000ms 256MiB

Balanced Team Formation

Balanced Team Formation

You are given n friends and an integer k. Each friend has a skill level represented by a positive integer. The task is to determine whether it is possible to form exactly k teams such that the sum of skill levels in each team differs by at most 1.

The idea is as follows: Let \(S\) be the total sum of skills. In an ideal balanced scenario, each team should have a sum of \(\lfloor S/k \rfloor\) or \(\lfloor S/k \rfloor + 1\). However, note that if any friend has a skill level greater than \(\lfloor S/k \rfloor + 1\), then the friend must exceed the allowed team sum and the distribution is impossible. Also if the number of teams is greater than the number of friends then it is impossible to form teams.

Output "YES" if it is possible to form such teams, otherwise output "NO".

inputFormat

The input is given from standard input (stdin) in the following format:

n k
s1 s2 ... sn

Where:

  • n is the number of friends,
  • k is the number of teams,
  • si denotes the skill level of the \(i\)-th friend.

outputFormat

Output a single line to standard output (stdout) containing either "YES" if it is possible to form k teams with balanced skill sums, or "NO" otherwise.

## sample
5 2
1 2 3 4 5
YES