#P6443. Optimal Team Formation

    ID: 19657 Type: Default 1000ms 256MiB

Optimal Team Formation

Optimal Team Formation

A university holds an annual informatics contest in which each team is composed of 1 male and 2 female contestants. Among all the contestants, there are \(m\) females and \(n\) males. The dean of one college wants to reduce the number of opponents by sending at most \(k\) contestants to an internship in a distant country; those who are sent will not be able to participate in the contest.

After sending \(k\) contestants away (in an optimal way), the remaining players will participate in the contest. Each team must consist exactly of 1 male and 2 females. In addition to the gender composition requirements, the total number of remaining contestants is \(m+n-k\) so that at most \(\left\lfloor \frac{m+n-k}{3} \right\rfloor\) teams can be formed.

Your task is to compute the maximum number of teams that can participate in the contest. In other words, if the maximum number of teams is \(t\), then they must satisfy:

[ \begin{aligned} &t \leq n, \ &2t \leq m, \ &t \leq \left\lfloor \frac{m+n-k}{3} \right\rfloor. \end{aligned} ]

The answer is:

[ t = \min\left(n, \left\lfloor \frac{m}{2} \right\rfloor, \left\lfloor \frac{m+n-k}{3} \right\rfloor\right). ]

</p>

inputFormat

The input consists of a single line containing three space-separated integers:

  • m: the number of female contestants,
  • n: the number of male contestants,
  • k: the maximum number of contestants that can be sent away for internship.

\(1 \leq m, n \leq 10^9\), and \(0 \leq k \leq m+n\).

outputFormat

Output a single integer representing the maximum number of teams that can be formed.

sample

20 10 5
8