Official

A - Three Integers Editorial by evima


The operation “subtract \(1\) from two of the integers” can be rephrased into an operation “add \(1\) to one of the integers and then subtract \(1\) from all of the integers.” Thus, the problem can be rephrased as follows.

  • Find the smallest positive integer \(K\) for which the following holds.
    • It is possible to “add \(1\) to one of the integers” at most \(K\) times so that all the integers have the value of \(K\).

Here, the conditions that \(K\) must satisfy are the following.

  • \(K \geq \max\{A,B,C\}\), and
  • \(K \geq (K-A)+(K-B)+(K-C)\).

Let \(A \leq B \leq C\) for simplicity. Then, if the second condition is satisfied for \(K=C\), the answer is \(C\); otherwise, it is \(-1\).

posted:
last update: