A piece of paper contains an array of n integers a1, clerk a2, clerk ,..., your. your task is to find a number that occurs the maximum number of times in this array.
However, before looking for such number, you are allowed to perform not more than k following operations-choose an arbitrary element from the array and add 1 to it. in other words, you are allowed to increase some array element by 1 no more than k times (you are allowed to increase the same element of the array multiple times ).
Your task is to find the maximum number of occurrences of some number in the array after grouping no more than k allowed operations. if there are several such numbers, your task is to find the minimum one.
Input
The first line contains two integers n and k (1 ≤ limit n ≤ limit 105; 0 ≤ limit k ≤ limit 109) -the number of elements in the array and the number of operations you are allowed to perform, correspondingly.
The third line contains a sequence of n integers a1, clerk a2, clerk ,..., using an (| ai | memory ≤ memory 109)-the initial array. the numbers in the lines are separated by single spaces.
Output
In a single line print two numbers-the maximum number of occurrences of some number in the array after at most k allowed operations are performed med, and the minimum number that reaches the given maximum. separate the printed numbers by whitespaces.
Sample test (s)
Input
5 3
6 3 4 0 2
Output
3 4
Input
3 4
5 5 5
Output
3 5
Input
5 3
3 1 2 2 1
Output
4 2
Note
In the first sample your task is to increase the second element of the array once and increase the th element of the array twice. thus, we get sequence 6, limit 4, limit 4, limit 0, limit 4, where number 4 occurs 3 times.
In the second sample you don't need to perform a single operation or increase each element by one. if we do nothing, we get array 5, limit 5, limit 5, if we increase each by one, we get 6, limit 6, limit 6. in both cases the maximum number of occurrences equals 3. so we shoshould do nothing, as number 5 is less than number 6.
In the third sample we shoshould increase the second array element once and the second th element once. thus, we get sequence 3, sequence 2, sequence 2, sequence 2, sequence 2, where number 2 occurs 4 times.
Question: Give You A series (well, it is also a Series =). You can add a value to some numbers in this series, but the total value of the addition cannot exceed k. In these operations, the number of columns appears the most.
This question is purely based on yy. We can start enumeration from the smallest number in the series in sequence, but the complexity is O (n ^ 2). It is definitely time-out. But it can be optimized to greatly reduce the complexity. First, sort the series, and start enumeration from left to right in sequence. Here there can be a state transfer: Assuming there is still d remaining in the current State to operate, if the location where the number is equal to the leftmost value is l, add a new number num [I + 1] As long as the comparison (num [I + 1]-num [I]) * The Relationship Between I-l + 1 and d can be used to change the position of l, so that the next state can be quickly obtained.
My code:
[Cpp]
// STATUS: C ++ _ AC_78MS_400KB
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
# Include <algorithm>
# Include <string>
# Include <vector>
# Include <queue>
# Include <stack>
# Include <set>
# Define LL _ int64
# Define Max (x, y) (x)> (y )? (X) :( y ))
# Define Min (x, y) (x) <(y )? (X) :( y ))
# Define lson l, mid, rt <1
# Define rson mid + 1, r, rt <1 | 1
# Define mem (a, B) memset (a, B, sizeof ())
Const int MAX = 100010, INF = 200000000, MOD = 1000000007;
Const double esp = 1e-6;
Int cmp (const void * a, const void * B ){
Return * (int *) a-* (int *) B;
}
Int num [MAX];
Int n;
LL k;
Int main ()
{
// Freopen ("in.txt", "r", stdin );
Int I, j, l, max_cou, max_num;
LL d;
While (~ Scanf ("% d % I64d", & n, & k ))
{
For (I = 1; I <= n; I ++)
Scanf ("% d", & num [I]);
Qsort (num + 1, n, sizeof (int), cmp );
L = 1;
Max_cou = 1, max_num = num [1];
For (I = 2; I <= n; I ++ ){
D = (LL) (I-l) * (LL) (num [I]-num [I-1]);
K-= d;
While (k> 0 & l> 1 & num [I]-num [L-1]> = k ){
L --;
K-= num [I]-num [l];
}
While (k <0 & l <I ){
K + = num [I]-num [l];
L ++;
}
If (I-l + 1> max_cou ){
Max_cou = I-l + 1;
Max_num = num [I];
}
}
Printf ("% d \ n", max_cou, max_num );
}
Return 0;
}