Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution
- {
- public static void Main()
- {
- while (true)
- {
- int[] nmArr = Console.ReadLine().Split(' ', 2).Select(Int32.Parse).ToArray();
- if (nmArr[0] <= 1)
- {
- return;
- }
- int m = nmArr[1];
- int[] numbers = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
- int closest = -1;
- for (int i = 0; i < numbers.Length; i++)
- {
- int first = numbers[i];
- for (int j = 0; j < numbers.Length; j++)
- {
- if (j == i)
- {
- continue;
- }
- int second = numbers[j];
- for (int k = 0; k < numbers.Length; k++)
- {
- if (k == j
- || k == i)
- {
- continue;
- }
- int third = numbers[k];
- int sum = first + second + third;
- if (sum > closest
- && sum <= m)
- {
- closest = sum;
- }
- }
- }
- }
- Console.WriteLine(closest);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement