#K74387. Closest Pair of Songs

    ID: 34186 Type: Default 1000ms 256MiB

Closest Pair of Songs

Closest Pair of Songs

You are given a list of song durations and a target duration. Your task is to find two distinct songs such that the sum of their durations is as close as possible to the target duration. Formally, if the two selected songs have durations s[i] and s[j] (with i < j), you need to minimize the difference:

\(\left| target - (s[i] + s[j]) \right|\)

If the sum exactly equals the target, output that pair immediately. Otherwise, output the pair that minimizes the absolute difference.

inputFormat

The input is read from standard input (stdin) and consists of two lines. The first line contains two integers n and target, where n is the number of songs. The second line contains n space-separated integers representing the durations of the songs.

\(1 \leq n \leq 10^5\), \(target \geq 1\), and each song duration is a positive integer.

outputFormat

Output two integers on a single line separated by a space, representing the durations of the two songs whose sum is closest to the target duration. The order of the two numbers should follow the natural order from the input after sorting.

## sample
6 900
250 300 150 600 1200 800
300 600