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. 对Android系统权限的认识

    Android系统是运行在Linux内核上的,Android与Linux分别有自己的一套严格的安全及权限机制 Android系统权限相关的内容 (一)linux文件系统上的权限 -rwxr-x--x ...

  2. Android so注入(inject)和Hook技术学习(三)——Got表hook之导出表hook

    前文介绍了导入表hook,现在来说下导出表的hook.导出表的hook的流程如下.1.获取动态库基值 void* get_module_base(pid_t pid, const char* modu ...

  3. Kafka 入门三问

    目录 1 Kafka 是什么? 1.1 背景 1.2 定位 1.3 产生的原因 1.4 Kafka 有哪些特征 消息和批次 模式 主题和分区 生产者和消费者 broker 和 集群 1.5 Kafka ...

  4. Appium-超过60s的应用场景如何处理

    前言: 最近在搞appium自动化项目,遇到超过60s的应用场景时,总是报错报错.如何解决呢?见下文. 报错信息: 2018-05-21 14:03:42:253 - [HTTP] <-- PO ...

  5. Kickstart Practice Round 2017---A

    Problem The Constitution of a certain country states that the leader is the person with the name con ...

  6. MySQL优化技巧总结

    MySQL优化的几个大方向 ① 硬件优化 ② 对MySQL配置参数进行优化(my.cnf)此优化需要进行压力测试来进行参数调整 ③ SQL语句方面的优化 ④ 表方面的优化   硬件优化 cpu,内存, ...

  7. Django 2.0 学习

    Django django是基于MTV结构的WEB框架 Model 数据库操作 Template 模版文件 View 业务处理 在Python中安装django 2.0 1 直接安装 pip inst ...

  8. Eclipse Todo Tasks 任务试图

    java - Find TODO tags in Eclipse - Stack Overflowhttps://stackoverflow.com/questions/16903046/find-t ...

  9. JMeter中返回Json数据的处理方法(转)

    Json 作为一种数据交换格式在网络开发,特别是 Ajax 与 Restful 架构中应用的越来越广泛.而 Apache 的 JMeter 也是较受欢迎的压力测试工具之一,但是它本身没有提供对于 Js ...

  10. C#复习笔记(4)--C#3:革新写代码的方式(查询表达式和LINQ to object(下))

    查询表达式和LINQ to object(下) 接下来我们要研究的大部分都会涉及到透明标识符 let子句和透明标识符 let子句不过是引入了一个新的范围变量.他的值是基于其他范围变量的.let 标识符 ...