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 kfollowing 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 ktimes (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

Note

In the first sample your task is to increase the second element of the array once and increase the fifth element of the array twice. Thus, we get sequence 6, 4, 4, 0, 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, 5, 5, if we increase each by one, we get 6, 6, 6. In both cases the maximum number of occurrences equals 3. So we should do nothing, as number 5 is less than number 6.

In the third sample we should increase the second array element once and the fifth element once. Thus, we get sequence 3, 2, 2, 2, 2, where number 2 occurs 4 times.

sol:因为只能加,所以这个很显然是用较小的数得到较大的数,而且肯定是满足单调性的,排序后二分即可

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m;
ll a[N],Qzh[N];
inline int TwoFind(int l,int r)
{
int Pos=r,ans=Pos+;
while(l<=r)
{
int mid=(l+r)>>;
if(a[Pos]*(Pos-mid+)-(Qzh[Pos]-Qzh[mid-])<=m)
{
ans=mid;
r=mid-;
}
else l=mid+;
}
return ans;
}
int main()
{
int i,ansx=,ansy=;
ll Sum=;
R(n); R(m);
for(i=;i<=n;i++) R(a[i]);
sort(a+,a+n+);
Qzh[]=; for(i=;i<=n;i++) Qzh[i]=Qzh[i-]+a[i];
for(i=;i<=n;i++)
{
int oo=TwoFind(,i);
if(i-oo+>ansx)
{
ansx=i-oo+; ansy=a[i];
}
}
W(ansx); Wl(ansy);
return ;
}
/*
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
*/

codeforces231C的更多相关文章

随机推荐

  1. SkylineGlobe系列软件对机器配置要求

    6.6版本: TerraExplorer for Desktop / Web Operating System: Windows® 7/ 8/ 10 - 64 bit recommended Proc ...

  2. 单链表的python实现

    首先说下线性表,线性表是一种最基本,最简单的数据结构,通俗点讲就是一维的存储数据的结构. 线性表分为顺序表和链接表: 顺序表示指的是用一组地址连续的存储单元依次存储线性表的数据元素,称为线性表的顺序存 ...

  3. ReactJs移动端兼容问题汇总

    汽车H5使用ReactJs问题汇总 Q:安卓4.4webview显示空白? A:初步怀疑是css属性没有加前缀引发的兼容问题,但添加后发现也不行,通过webview调试后控制台输出Set is und ...

  4. lower_bound函数与upper_bound函数

    头文件 : algorithm vector<int>a a中的元素必须升序,用的是二分 lower_bound(a.begin(),a.end(),k) 返回a容器中,最右边的小于等于k ...

  5. STL vector用法

    基本操作 1.构造函数 vector():创建一个空vector vector(int nSize):创建一个vector,元素个数为nSize vector(int nSize,const t&am ...

  6. 亲测可以永久破解2018版本的pycharm

    pycharm是很强大的开发工具,但是每次注册着实让人头疼.网络上很多注册码.注册服务器等等.但都只是一年或者不能用:为次有如下解决方案.亲测有效!!! 如果想让pycharm永久被激活,比如截止日到 ...

  7. Python编码与变量

    (一)Python执行的方式 Window: 在CMD里面,使用 Python + 相对路径/绝对路径 在解释器里面,直接输入,一行代码一行代码的解释 Linux: 明确地指出用Python解释器来执 ...

  8. 几个jdbc小技巧

    版本:jdk:1.6mysql-connector-5.0.8 1.如何用jdbc判断某个基本表是否存在 一种比较“笨”的方法:    try{         stmt.executeQuery( ...

  9. stark组件数据库管理软件的总结

      1.stark - 总结 用到的知识点: 1.单例模式 2.继承 3.反射 4.面向对象 5.modelform 1.注册表 单例模式 site = StarkSite() 2.生成url url ...

  10. js上传视频(jquery.form.js)

    // 上传目标触发点 <input type="file" class="upvideo" name="upvideo" id=&qu ...