Baltic OI '10 P5 - Candies
View as PDFBaltic Olympiad in Informatics: 2010 Day 2, Problem 2
Kristian works as a shopkeeper and sells candies. There are  packages in his shop and each
of them may contain a different number of candies. When a customer comes and asks for 
candies, Kristian has to bring some packages, such that the total number of candies in those
packages is equal to 
. If he is unable to do this, for example if someone asks for 
 candies
and there are only 
 packages with 
 candies in each of them, often the customer gets upset and
leaves.
Because of that, Kristian wanted to know how many different options he could provide to the next customer with the packages he currently has. He managed to solve this problem and now he is wondering what to do to improve the result. He wants to open one package and change the number of candies in it so that the total number of distinct options he can offer to the customer will increase as much as possible.
Constraints
Input Specification
The first line of the text file candies.in contains one integer . The
second line contains a sequence of 
 space-separated integers 
, describing the numbers of candies in each package.
Output Specification
The only line of output should contain two integers  and 
 separated by a single space.
They mean that Kristian should take a package with 
 candies and change the number of candies to 
 in order to achieve the maximum distinct options.
 has to be equal to one of 
.
Since there can be many optimal results, output the one with the minimum  value. In the case of a tie, choose the one with the minimum possible 
.
You can assume that Kristian can increase the total number of distinct orders he can serve by altering a single package.
Sample Input
4
1 3 4 4
Sample Output
4 9
Explanation for Sample Output
With the packages described in the first sample input file, Kristian can serve orders
of  different sizes, namely 
 and 
. After changing a package with 
 candies
to 
 candies, he could serve orders of size 
 and 
, which
makes 
 distinct options in total. This is the maximum amount of options he can achieve.
Comments