To Add or Not to Add

Time Limit: 2000ms
Memory Limit: 262144KB

This problem will be judged on CodeForces. Original ID: 231C
64-bit integer IO format: %I64d      Java class name: (Any)

 

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.

 

Sample Input

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

Source

 
解题:二分,排序后二分,这也可以二分啊?尼玛,还真可以二分!好吧,二分就二分吧
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
int d[maxn],n,k,temp;
LL sum[maxn];
int check(int p){
for(int i = p; i <= n; i++){
if((LL)d[i]*p - sum[i]+sum[i-p] <= k)
return i;
}
return -;
}
int main(){
int i,lt,rt,mid,num,ans;
while(~scanf("%d%d",&n,&k)){
for(i = ; i <= n; i++)
scanf("%d",d+i);
sort(d+,d+n+);
sum[] = ;
for(i = ; i <= n; i++)
sum[i] = sum[i-]+d[i];
lt = ;
rt = n;
while(lt <= rt){
mid = (lt+rt)>>;
temp = check(mid);
if(temp == -) rt = mid-;
else{
ans = temp;
num = mid;
lt = mid+;
}
}
printf("%d %d\n",num,d[ans]);
}
return ;
}

xtu summer individual 5 A - To Add or Not to Add的更多相关文章

  1. 在 VS 类库项目中 Add Service References 和 Add Web References 的区别

    原文:在 VS 类库项目中 Add Service References 和 Add Web References 的区别 出身问题: 1.在vs2005时代,Add Web Reference(添加 ...

  2. git add -A 和 git add . 的区别

    git add -A和 git add .   git add -u在功能上看似很相近,但还是存在一点差别 git add . :他会监控工作区的状态树,使用它会把工作时的所有变化提交到暂存区,包括文 ...

  3. git add -A和git add . 的区别

    git add -A和 git add . git add -u在功能上看似很相近,但还是有所差别. git add . :他会监控工作区的状态树,使用它会把工作时的所有变化提交到暂存区,包括文件内容 ...

  4. add jars、add external jars、add library、add class folder的区别

    add external jars = 增加工程外部的包add jars = 增加工程内包add library = 增加一个库add class folder = 增加一个类文件夹 add jar是 ...

  5. xtu summer individual 5 E - Burning Bridges

    Burning Bridges Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Origina ...

  6. xtu summer individual 4 C - Dancing Lessons

    Dancing Lessons Time Limit: 5000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...

  7. xtu summer individual 3 C.Infinite Maze

    B. Infinite Maze time limit per test  2 seconds memory limit per test  256 megabytes input standard ...

  8. xtu summer individual 2 E - Double Profiles

    Double Profiles Time Limit: 3000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...

  9. xtu summer individual 2 C - Hometask

    Hometask Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origin ...

随机推荐

  1. [Usaco2005]Part Acquisition

    Description The cows have been sent on a mission through space to acquire a new milking machine for ...

  2. [Usaco2009 Feb]庙会捷运Fair Shuttle

    Description 公交车一共经过N(1<=N<=20000)个站点,从站点1一直驶到站点N.K(1<=K<=50000)群奶牛希望搭乘这辆公交车.第i群牛一共有Mi(1& ...

  3. Fighting

    class Demo { public static void main(String[] args) { int a=3,b=8; int c=(a>b)?a++:b++; System.ou ...

  4. C#中如何判断键盘按键和组合键

    好记性不如烂笔头子,现在记录下来,不一定会有很详尽的实例,只写最核心的部分. C# winform的窗体类有KeyPreview属性,可以接收窗体内控件的键盘事件注册.窗体和控件都有KeyDown,K ...

  5. vue watch监听对象及对应值的变化

    data:{ a:1, b:{ value:1, type:1, } }, watch:{ a(val, oldVal){//普通的watch监听 console.log("a: " ...

  6. Swift 基础语法入门(一)

    一.变量和常量 1.声明常量和变量 用let来声明常量  let radius = 10 用var来声明变量 var age = 20   或者是var x = 0.0, y = 0.0, z = 0 ...

  7. 利用Wamp在本地搭建一个wordpress站点

    原文链接:利用Wamp在本地搭建一个wordpress站点 有时候我们会想搭建一个自己的站点,可是由于只是想自己访问,就不是很想为这个站点在买一个服务器和域名,那我们可能首先就想到把自己电脑当做服务器 ...

  8. Android习惯--Activity启动方法

    public void Text extends Activity{ public void static actionStart(Context context, int i, String str ...

  9. 通过SSDT HOOK实现进程保护和进程隐藏

    ---恢复内容开始--- 首先,我要说一件很重要的事,本人文采不好,如果哪里说的尴尬了,那你就尴尬着听吧...... SSDT HOOK最初貌似源于Rookit,但是Rookit之前有没有其他病毒使用 ...

  10. 迅为电子HMI人机界面|CAN总线触摸屏

    本文转自迅为:http://www.topeet.com 协议特色: 1. 支持所有 CAN 协议,例如常用的 J1939 和 CANopen 协议. 2. 提供高度开放的 CAN 帧的编辑界面,用户 ...