#C1555. Maximum Increasing Triplet Sum
Maximum Increasing Triplet Sum
Maximum Increasing Triplet Sum
You are given an integer \( N \) and an array \( A \) of \( N \) integers. Your task is to find three indices \( i, j, k \) (with \( i < j < k \)) such that the corresponding triplet \( (A_i, A_j, A_k) \) satisfies \( A_i < A_j < A_k \). The goal is to maximize the sum \( A_i + A_j + A_k \). If no such triplet exists, output \(-1\).
Input Format:
- The first line contains a single integer \( N \), the number of elements in the array.
- The second line contains \( N \) space-separated integers representing the array \( A \).
Output Format:
- Output a single integer representing the maximum sum of an increasing triplet, or \(-1\) if no valid triplet is found.
inputFormat
The first line of the input contains a single integer \( N \). The second line contains \( N \) space-separated integers representing the array \( A \).
outputFormat
Output a single integer: the maximum sum of an increasing triplet in the array if it exists; otherwise, output \(-1\).
## sample5
10 20 30 40 50
120