PivotOJ

A Musical Question

시간 제한: 11000ms메모리 제한: 1024MB출처: ICPC ECNA 2022-2023BOJ 27610

문제

Bob Roberts likes to listen to music while he drives, but the car he owns is a little antiquated. No Bluetooth or USB connections here, but at least he has a CD player, so he's been transferring a lot of his music to CDs. At the moment he has only two CDs left and would like to get as much of his remaining music as possible on them. Given the capacity of the CDs and collection of songs, can you help him find the maximum number of minutes of music he can put on the two CDs?

입력

Input starts with a line containing two integers cc nn, where cc (1c1000)(1 \leq c\leq 1\,000) is the number of minutes of music each CD can hold, and nn (1n1000)(1 \leq n \leq 1\,000) is the number of songs to select from. Following this is a single line containing nn positive integers indicating the length (in minutes) of each of the songs. No song will be longer than 10001\,000 minutes.

출력

Output the amount of music on each CD, in minutes, that maximizes the total amount of music that Bob can transfer to the two CDs. Display the time of the larger-filled CD first. If there is a tie, use the solution which minimizes the time difference between the two CDs.

예제

예제 1

입력
100 5
10 20 40 60 85
출력
100 95

예제 2

입력
100 5
10 20 30 40 50
출력
80 70
코드를 제출하려면 로그인하세요.