【链接】 我是链接,点我呀:)

【题意】

题意

【题解】

把数组排个序,
显然优先用大的且小于枚举的数字a[i]的数字变成a[i]
那么肯定有一个范围j.
然后a[j~i-1]都能在k花费以内变成a[i]
然后考虑i++
这个时候肯定最好的情况还是a[j~i]都能变成a[i]
(至少j不会变小,因为数字a[i]都变大了,再往左的话,花费肯定超过k了)
所以根据上面的推理,维护一个最左的端点j吧)

【代码】

#include <bits/stdc++.h>
#define ll long long
using namespace std; const int N = 1e5; int n,k;
ll a[N+10],sum; int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >>n >> k;
for (int i = 1;i <= n;i++) cin >> a[i];
sort(a+1,a+1+n);
int l = 1;sum = 0;
int anslen = 0,num;
for (int i = 1;i <= n;i++){
sum = sum + a[i];
while(1LL*(i-l+1)*a[i]-sum>k) {
sum-=a[l];
l++;
}
if ( (i-l+1)>anslen){
anslen = (i-l+1);
num = a[i];
}
}
cout<<anslen<<" "<<num<<endl;
return 0;
}

【Codeforces 231C】To Add or Not to Add的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  3. 【codeforces 757D】Felicity's Big Secret Revealed

    [题目链接]:http://codeforces.com/problemset/problem/757/D [题意] 给你一个01串; 让你分割这个01串; 要求2切..n+1切; 对于每一种切法 所 ...

  4. 【codeforces 716D】Complete The Graph

    [题目链接]:http://codeforces.com/problemset/problem/716/D [题意] 给你一张图; 这张图上有一些边的权值未知; 让你确定这些权值(改成一个正整数) 使 ...

  5. 【codeforces 501D】Misha and Permutations Summation

    [题目链接]:http://codeforces.com/problemset/problem/501/D [题意] 给你两个排列; 求出它们的字典序num1和num2; 然后让你求出第(num1+n ...

  6. 【codeforces 404D】Minesweeper 1D

    [题目链接]:http://codeforces.com/problemset/problem/404/D [题意] 让你玩一个1维的扫雷游戏; 游戏的描述由数字0..2以及符号*表示; 分别表示这个 ...

  7. 【codeforces 589G】Hiring

    [题目链接]:http://codeforces.com/problemset/problem/589/G [题意] 有n个人; 每个人每天在开始工作之前,都需要di单位的准备时间,然后才能开始工作; ...

  8. 【codeforces 816B】Karen and Coffee

    [题目链接]:http://codeforces.com/contest/816/problem/B [题意] 给你很多个区间[l,r]; 1<=l<=r<=2e5 一个数字如果被k ...

  9. 【codeforces 466D】Increase Sequence

    [题目链接]:http://codeforces.com/problemset/problem/466/D [题意] 给你n个数字; 让你选择若干个区间; 且这些区间[li,ri]; 左端点不能一样; ...

随机推荐

  1. Unix\Linux | 总结笔记 | man帮助

    0.目录 手册页分类说明 man手册中的段落说明     1.  man手册页分类 man1  普通用户可以执行的命令帮助 man2  系统调用.内核函数的说明帮助 man3   库函数说明帮助 ma ...

  2. 题解报告:hdu 2093 考试排名

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2093 Problem Description C++编程考试使用的实时提交系统,具有即时获得成绩排名的 ...

  3. Android Dialogs(4)Dialog事件处理

    Passing Events Back to the Dialog's Host When the user touches one of the dialog's action buttons or ...

  4. overlaps the location of another project Zendstudio导入已经存在的目录

    转 http://blog.csdn.net/kdchxue/article/details/50633745 最近弄zendstuido导入已经存在的项目,找了很多地方终于找到了导入的方法,特别记录 ...

  5. 安卓(Android)关于 RecyclerView 不能填充满宽度

    RecyclerView 不能填充满屏幕宽度 RecyclerView 的 Adapter 在使用是,一定要 @Overridepublic RecyclerView.ViewHolder onCre ...

  6. iOS Programming Views :Redrawing and UIScrollView

    iOS Programming Views :Redrawing and UIScrollView  1.1 event  You are going to see how views are red ...

  7. linux下php开启pdo扩展

    前提:网页报错 为解决问题:Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' 解决方案 : 下载安装PHP_MYSQL扩展 wget http:// ...

  8. Python之三元运算、集合、函数

    一.三元运算符 三元运算符就是在赋值变量的时候,可以直接加判断,然后赋值 格式:[on_true] if [expression] else [on_false] res = 值1 if 条件 els ...

  9. WPF学习- AllowDrop 用户控件启用拖放功能

    知识点: 创建自定义用户控件(UserControl) 使用户控件成为拖动源 使用户控件成为放置目标 使面板能够接收从用户控件放置的数据 创建项目: 1.新建WPF项目(Wpf-AllowDrop) ...

  10. Js 之图片懒加载插件

    一.PC端(lazyload) 1.引入js文件 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.m ...