#P6437. Maximum Triple Sum Under Limit

    ID: 19651 Type: Default 1000ms 256MiB

Maximum Triple Sum Under Limit

Maximum Triple Sum Under Limit

You are given n positive integers \(a_1, a_2, \dots, a_n\) and an integer \(m\). Your task is to choose three distinct numbers from the list so that their sum is at most \(m\) and output the maximum possible sum.

If no three numbers can satisfy the condition, the answer will be 0.

inputFormat

The first line contains two integers \(n\) and \(m\) separated by a space.

The second line contains \(n\) positive integers \(a_1, a_2, \dots, a_n\) separated by spaces.

outputFormat

Output a single integer, the maximum sum of any three numbers that is less than or equal to \(m\>.

sample

5 20
4 5 6 7 8
20