Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Hints : The 67th 6-7 Integer Problem

You must flip the sign of exactly six numbers. Equivalently, how many numbers keep their original sign?

Answer to Hint 1: Exactly one number is left unchanged (not negated); the other six are multiplied by $-1$.

If the unchanged number is $a_k$, how does the new total relate to the original sum $S = a_1 + \cdots + a_7$?

Answer to Hint 2: Negating the other six replaces their total $S - a_k$ by $-(S - a_k)$. The new sum is

$$a_k - (S - a_k) = 2a_k - S.$$

So for a fixed multiset, you only choose which index $k$ is left unchanged. What should you maximize?

Answer to Hint 3: Since $S$ is fixed, maximize $2a_k - S$ by maximizing $a_k$: leave the largest value non-negated.

To compute quickly: sort the seven values ascending; the largest is the last element. Its contribution is that maximum minus the sum of the other six.

Answer to Hint 4: After sorting as $A[0] \le \cdots \le A[6]$, the answer is

$$A[6] - (A[0] + A[1] + \cdots + A[5]).$$