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. 【LOJ 3049】「十二省联考 2019」字符串问题

    这个D1T2绝对有毒... 首先我们构造一把反串的后缀自动机. 然后我们就需要找到每一个子串在SAM上的节点. 这个可以通过扫描线+树上倍增处理. 首先我们把所有的子串按照左端点排序, 然后从右往左扫 ...

  2. c++中vector类的用法

    概括:向量(Vector)是一个封装了动态大小数组的顺序容器(Sequence Container).跟任意其它类型容器一样,它能够存放各种类型的对象.可以简单的认为,向量是一个能够存放任意类型的动态 ...

  3. Mybatis学习总结(五)——动态sql

    MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其他类似框架的经验,你就能体会到根据不同条件拼接 SQL 语句有多么痛苦.拼接的时候要确保不能忘了必要的空格,还要注意省掉 ...

  4. Generative Adversarial Nets[Vanilla]

    引言中已经较为详细的介绍了GAN的理论基础和模型本身的原理.这里主要是研读Goodfellow的第一篇GAN论文. 0. 对抗网络 如引言中所述,对抗网络其实就是一个零和游戏中的2人最小最大游戏,主要 ...

  5. sklearn 数据预处理1: StandardScaler

    作用:去均值和方差归一化.且是针对每一个特征维度来做的,而不是针对样本. [注:] 并不是所有的标准化都能给estimator带来好处. “Standardization of a dataset i ...

  6. Git&Github基本操作与分支管理

    Git的原理涉及快照流.链表.指针等,这里不作过多叙述. 1.基本操作 git init 创建一个 Git 仓库 git clone [url] 拷贝一个 Git 仓库到本地 git add [fil ...

  7. Hibernate各种基本注解及一对一(多)关系映射采坑笔记

    hibernate提供两种方式配置关系映射,一种XMl配置,一种注解.SpringBoot已经自带了hibernate注解方式,我也是特别喜欢使用注解,特此记下常用的知识点. 1.基本注解 @Tabl ...

  8. python--Numpy and Pandas 笔记01

    博客地址:http://www.cnblogs.com/yudanqu/ 1 import numpy as np import pandas as pd from pandas import Ser ...

  9. 跨域访问-需要设置HTTP响应标头

    前提:服务端网站的配置(被请求的网站) 1.需要在IIS服务器站点的功能视图中设置HTTP响应标头: 2.双击“HTTP响应标头”进入设置界面 3.点击右侧添加按钮弹出窗口 4.填入需要设置的信息 名 ...

  10. Verilog语法遗漏点

    1 关于参数定义 Parameter:parameter只能定义在端口生命的前面,如 Input[whith:0] a; Parameter whith=4; 这样的参数定义出现在声明的后面会报错 2 ...