#P7521. Maximizing Modular Sum Triplet
Maximizing Modular Sum Triplet
Maximizing Modular Sum Triplet
Given n positive integers \(a_i\), select three distinct indices \(i\), \(j\), and \(k\) (with \(i \neq j\), \(i \neq k\), and \(j \neq k\)) such that the value of \((a_i + a_j)\bmod a_k\) is maximized. Output the maximum result among all valid triplets.
inputFormat
The input begins with a line containing an integer (n), the number of elements. The second line contains (n) positive integers separated by spaces.
outputFormat
Output a single integer representing the maximum value of ((a_i + a_j)\bmod a_k) over all triplets where (i), (j), and (k) are distinct.
sample
3
1 2 3
0
</p>