Олимпиадный тренинг

Задача 38997. Demo 2022. Problem analysis


The system administrator creates an archive of user files once a week. However, the size of the disk where it places the archive may be less than the total size of the archived files. It is known how much space each user's file occupies. Given information about the size of user files and the free space on the archive disk, determine the maximum number of users whose files can be archived, as well as the maximum size of an existing file that can be stored in the archive, provided that the files of the maximum possible number of users are saved. Write a program that calculates  the maximum number of users whose files can be archived, as well as the maximum size of an existing file that can be archived, provided that the files of the maximum possible number of users are stored.

Input:
The first line contains two numbers: S – free disk space (a natural number not exceeding 100,000) and – number of users (a natural number not exceeding 10000). The next N lines contain the values ​​of each user's file sizes (all natural numbers, not exceeding 100), each on a separate line.

Output:
Print two space-separated numbers on one line: first, the largest number of users whose files can be archived, then the maximum size of an existing file that can be archived, provided that the files of the maximum possible number of users are stored.
 
Example
# Input Output
1 100 4
80
30
50
40
2 50

With this initial data, you can save the files of a maximum of two users. The possible sizes of these two files are 30 and 40, 30 and 50 or 40 and 50. The largest file size of the listed – 50, so the answer for this example is: 2 50