#K88407. Maximum Number of Teams

    ID: 37301 Type: Default 1000ms 256MiB

Maximum Number of Teams

Maximum Number of Teams

You are given n participants along with their respective skill levels and a number k representing the team size requirement. A valid team is one where each member has a unique skill, i.e. no two members in the same team share the same skill. Your task is to form as many teams as possible such that each team has exactly k participants with distinct skills.

More formally, if a team is formed by selecting exactly k participants with distinct skills, then the maximum number of teams you can form is the largest number T such that it is possible to partition participants into T groups satisfying that condition.

The selection process can be described by repeatedly removing one participant from k different skill groups until no further complete team can be formed. In mathematical terms, if we denote by \(f_i\) the frequency of participants with skill \(i\), then each team reduces the frequency of \(k\) distinct skills by one. The process terminates when the number of distinct skills with at least one remaining participant is less than k.

Input/Output specifications and examples are provided below.

inputFormat

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

n k
s1 s2 ... sn

where:

  • n (integer) is the number of participants.
  • k (integer) is the size of each team (i.e. the number of distinct skills required).
  • si are the skill levels of the participants.

outputFormat

Output a single integer representing the maximum number of teams that can be formed. The answer should be printed on standard output (stdout).

## sample
6 3
1 2 3 1 2 3
2