#K3976. Maximize Money Spent on Two Dishes
Maximize Money Spent on Two Dishes
Maximize Money Spent on Two Dishes
In a bustling market, there are n dishes available, each with a unique price. You are given a total amount \(m\) to spend. Your task is to select exactly two distinct dishes such that their combined price is as close as possible to \(m\) without exceeding it.
If no two dishes can be bought without exceeding \(m\), output \(-1\).
Input Format: The first line contains two integers \(n\) and \(m\) separated by a space. The second line contains \(n\) space-separated integers representing the prices of the dishes.
Output Format: Output a single integer representing the maximum total price of two dishes without exceeding \(m\), or \(-1\) if such a pair cannot be found.
inputFormat
The first line contains two integers (n) and (m). The second line contains (n) integers representing the prices of the dishes.
outputFormat
A single integer: the maximum sum of prices of two dishes that does not exceed (m), or (-1) if no valid pair exists.## sample
5 10
2 4 6 8 3
10