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. 一篇自己都看不懂的点分治&点分树学习笔记

    淀粉质点分治可真是个好东西 Part A.点分治 众所周知,树上分治算法有$3$种:点分治.边分治.链分治(最后一个似乎就是树链剖分),它们名字的不同是由于分治方式的不同的.点分治,顾名思义,每一次选 ...

  2. 【原创】JAVA8之妙用Optional解决NPE问题

    引言 在文章的开头,先说下NPE问题,NPE问题就是,我们在开发中经常碰到的NullPointerException.假设我们有两个类,他们的UML类图如下图所示 在这种情况下,有如下代码 user. ...

  3. ECS上配置FTP Filezilla

    又来搞华为ECS 第一,服务器安装服务端 第二,设置被动模式,把服务器的公网IP填好 第三,生成一个服务器证书,客户端连接时接受 第四,设置自定义的被动连接端口比如 9000-9050 第五,去ECS ...

  4. matplotlib 入门之Sample plots in Matplotlib

    文章目录 Line Plot One figure, a set of subplots Image 展示图片 展示二元正态分布 A sample image Interpolating images ...

  5. 有界算子p129

    ? 如果我把这里的1改成2,把1/(a-b) 换成1/2(a-b) 为什么不能是? 2. 这里的x是关于t的函数,为什么x属于 结果了?和x应该没有关系呀? 3. 那为什么T的范数不是一个固定值?为什 ...

  6. PEP 8 python编程规范

    一 代码编排 缩进.4个空格的缩进(编辑器都可以完成此功能),不使用Tap,更不能混合使用Tap和空格. 每行最大长度79,换行可以使用反斜杠,最好使用圆括号.换行点要在操作符的后边敲回车. 类和to ...

  7. pycharm异常问题之Unable to save settings: Failed to save settings. Please restart PyCharm

    pycharm异常之Unable to save settings: Failed to save settings. Please restart PyCharm 今天一不小心将电脑关了,但是关机之 ...

  8. Python_函数的有用信息、带参数的装饰器、多个装饰器装饰一个函数

    函数的有用信息 代码1: def login(username, password): """ 此函数需要用户名,密码两个参数,完成的是登录的功能. :return: T ...

  9. http/https与websocket的ws/wss的关系以及通过Nginx的配置

    http/https与websocket的ws/wss的关系 - 哒哒哒 - CSDN博客 https://blog.csdn.net/Garrettzxd/article/details/81674 ...

  10. day 7-14 数据库完整性约束

    一. 介绍 约束条件与数据类型的宽度一样,都是可选参数 作用:用于保证数据的完整性和一致性 主要分为: PRIMARY KEY 标示该字段为表的主键,可以唯一的标示记录 FOREIGN KEY 标示该 ...