To Add or Not to Add CodeForces - 231C

题目

A piece of paper contains an array of n integers a1, a2, ..., an. 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 performing 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 ≤ n ≤ 105; 0 ≤ k ≤ 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, a2, ..., an (|ai| ≤ 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, and the minimum number that reaches the given maximum. Separate the printed numbers by whitespaces.

Examples

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

题意

给你一个长度为n的整数序列,你最多有k次操作(k次操作可以不完全用上),每次可以将数组中的一个数加1(一个数字可以多次操作),问你经过适当的操作后,数组中出现的次数最多的数字是什么(如果次数相同,输出最小的那个数字)。先输出次数,再输出那个数。

分析

n的范围是1e5,不可能暴力。先排序,把前缀和存起来,然后遍历该数组,用二分思想去找该数组中,在满足条件的情况下,有多少个数能转换成a[ i ]。

代码

#include<iostream>
#include<cstdio>
#include<string.h>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+5;
ll a[N],sum[N];
ll cal(ll l,ll r)//计算从l--r都转换成a[r]需要多少  
{
	ll tmp=sum[r]-sum[l-1];
	tmp=a[r]*(r-l+1)-tmp;
	return tmp;
}
ll erfen(ll s,ll k)//二分,计算该数组中能转换成ar[s]的数有多少  
{
	ll l=1,r=s;
	while(l<r)
	{
		ll mid=(l+r)/2;
		ll tmp=cal(mid,s);
		if(tmp>k)
			l=mid+1;
		else
			r=mid;
	}
	return s-l+1;
}
int main()
{
	ll n,k;
	while(~scanf("%lld%lld",&n,&k))
	{
		for(int i=1;i<=n;i++)
			scanf("%lld",&a[i]);
		sort(a+1,a+n+1);
		sum[0]=0;
		for(int i=1;i<=n;i++)
			sum[i]=sum[i-1]+a[i];
		ll count=0,num;
		for(ll i=1;i<=n;i++)//因为排序了,所以从小的开始,找到的一定是小的  
		{
			ll tmp=erfen(i,k);
			if(count<tmp)
			{
				count=tmp;
				num=a[i];
			}
		}
		printf("%lld %lld\n",count,num);
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值