#K68782. Maximum Sum of Three Elements
Maximum Sum of Three Elements
Maximum Sum of Three Elements
You are given an array of n integers. Your task is to choose three distinct elements from the array such that their sum is maximized. Output the maximum sum and the 1-based indices of the chosen elements in ascending order.
Formally, let the array be \(a_1, a_2, \dots, a_n\). You need to find three distinct indices \(i, j, k\) such that
[ a_i + a_j + a_k = \max_{1 \leq i < j < k \leq n} (a_i + a_j + a_k), ]
and output the maximum sum on the first line, and the three indices (in ascending order) on the second line.
inputFormat
The first line contains a single integer n (\(n \ge 3\)), representing the number of elements in the array.
The second line contains n space-separated integers \(a_1, a_2, ..., a_n\), representing the elements of the array.
outputFormat
Output two lines:
- The first line should contain the maximum sum achievable by selecting three distinct elements.
- The second line should contain three 1-based indices of these elements in ascending order, separated by spaces.
5
1 2 3 4 5
12
3 4 5
</p>