题干:

You are given an array aa of nn integers, where nn is odd. You can make the following operation with it:

  • Choose one of the elements of the array (for example aiai) and increase it by 11(that is, replace it with ai+1ai+1).

You want to make the median of the array the largest possible using at most kkoperations.

The median of the odd-sized array is the middle element after the array is sorted in non-decreasing order. For example, the median of the array [1,5,2,3,5][1,5,2,3,5] is 33.

Input

The first line contains two integers nn and kk (1≤n≤2⋅1051≤n≤2⋅105, nn is odd, 1≤k≤1091≤k≤109) — the number of elements in the array and the largest number of operations you can make.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109).

Output

Print a single integer — the maximum possible median after the operations.

Examples

Input

3 2
1 3 5

Output

5

Input

5 5
1 2 1 1 1

Output

3

Input

7 7
4 1 2 4 3 4 4

Output

5

Note

In the first example, you can increase the second element twice. Than array will be [1,5,5][1,5,5] and it's median is 55.

In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is 33.

In the third example, you can make four operations: increase first, fourth, sixth, seventh element. This way the array will be [5,1,2,5,3,5,5][5,1,2,5,3,5,5] and the median will be 55.

题目大意:

给你n个数,让你可以最多执行K次操作,每次操作使得一个数+1,问你操作完之后的序列的中位数最大是多大。

解题报告:

水题,排序后发现只跟后一般的数有关。考虑每次操作,操作前半个区间的数字没有意义。操作后面的数字的话也没有意义,因为看的是中位数,所以只有中间这个数字变大,答案才能变大。(也就是说使得答案变大的方式只有使得中间这个数字变大)然后模拟这个过程就行了。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
ll a[MAX];
map<ll,ll> mp;
set<ll> ss;
int main()
{int n,k;cin>>n>>k;for(int i = 1; i<=n; i++) cin>>a[i];sort(a+1,a+n+1);for(int i = (n+1)/2; i<=n; i++) ss.insert(a[i]),mp[a[i]]++;ll num = mp[a[(n+1)/2]];//当前这个大点集的点的个数 ll ans = a[(n+1)/2];while(k>0) {auto it = ss.upper_bound(ans);if(it == ss.end()) break;ll ci = (*it-ans)*num;if(ci <= k) {k -= ci;ans = *it;num += mp[*it];}else {ans += (k / (num));k = 0;    }}if(k > 0) ans += k/(num);cout << ans << endl;return 0 ;
}
//16:16-16:26

总结:刚开始WA了一发,是因为else中k=0和ans+=(k/sum)这两句写反了,,,真服了自己了。

【CodeForces - 1201C】Maximum Median(思维,水题)相关推荐

  1. 【Disturbed People】【CodeForces - 1077B】(思维水题)

    题目: There is a house with nn flats situated on the main street of Berlatov. Vova is watching this ho ...

  2. codeforces 1060a(思维水题)

    Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", ...

  3. FZU 2230 2230 翻翻棋(思维水题)

    Problem Description 象棋翻翻棋(暗棋)中双方在4*8的格子中交战,有时候最后会只剩下帅和将.根据暗棋的规则,棋子只能上下左右移动,且相同的级别下,主动移动到地方棋子方将吃掉对方的棋 ...

  4. CF Round #426 (Div. 2) The Useless Toy 思维 水题

    题目链接: http://codeforces.com/contest/834/problem/A 题目描述: 输入起始状态和结束状态和数列长度, 判断旋转方向是顺时针逆时针还是不合理 解题思路: 长 ...

  5. Codeforces 864 A Fair Game 水题

    题目链接: http://codeforces.com/problemset/problem/864/A 题目描述: 看不是是不是一串数中只有两种数且这两种数字的数量是相同的 解题思路: 水题, 水过 ...

  6. 【CodeForces - 569B】Inventory (水题)

    题干: Companies always have a lot of equipment, furniture and other things. All of them should be trac ...

  7. CodeForces - 1141D Colored Boots(暴力+水题)

    题目链接:点击查看 题目大意:给出两个字符串s和t,两个字符串中相同的字母可以匹配,问号可以和任意字符匹配,现在问两个字符串最多能匹配多少个字符,并给出匹配的下标 题目分析:挺好玩的一道水题,大体思路 ...

  8. 【CodeForces - 1038A 】Equality (思维水题,预处理字符串)

    题干: You are given a string ss of length nn, which consists only of the first kk letters of the Latin ...

  9. 【CodeForces - 707B】Bakery(思维水题)

    Bakery Descriptions 玛莎想在从1到n的n个城市中开一家自己的面包店,在其中一个城市烘焙松饼. 为了在她的面包房烘焙松饼,玛莎需要从一些储存的地方建立面粉供应.只有k个仓库,位于不同 ...

  10. CodeForces - 622C Not Equal on a Segment(思维+水题)

    题目链接:点击查看 题目大意:先给出一个长度为n的数列,然后给出m次询问,每次询问的格式是l,r,x,其中[l,r]代表的是数列的下标范围,要求我们输出任意一个在区间[l,r]内值不等于x的下标 题目 ...

最新文章

  1. vysor原理以及Android同屏方案
  2. 连线IBM大数据案例 让大数据接地气
  3. Linux下双线双ip访问内网服务器之另类解决办法
  4. Codeforces Round #715 (Div. 2)
  5. linux 挂载有数据硬盘分区,linux下磁盘分区、挂载知多少
  6. UBIFS - UBI File-System
  7. std::call_once写单列模式
  8. 7.1 pdo 宝塔面板php_宝塔面板PHP7.2 安装mcrypt扩展
  9. 在Linux上安装ant环境
  10. STM32_HAL新建工程
  11. 海康SDK接口调用的主要流程
  12. 微信开放平台-移动应用
  13. WiFi大师小程序3.0.9独立版源码
  14. 小熊派使SPI驱动TFT-LCD(ST7789)显示试验
  15. 强化学习@AAAI2019
  16. python标准库复数运算包cmath
  17. When Observable completes without emitting, toPromise() will successfully resolve with undefined.
  18. TypeScript数据类型
  19. 计算机 图像处理 ei 期刊,【EA-ISET协会】中科院3区视觉图像处理类SCIEI源刊征稿...
  20. idea 在创建maven 时出现报错org.codehaus.plexus.component.repository.exception.ComponentLookupException:

热门文章

  1. 数据结构四——散列表(下)
  2. [剑指offer][JAVA]面试题第[34]题[二叉树中和为某一值的路径][回溯]
  3. web前端开发——HTML学习
  4. python列表统计每个元素出现次数_python 统计list中各个元素出现的次数的几种方法...
  5. 条形图坐标轴_解密咨询报告中常见的双层条形图的制作方法
  6. 使用rpm包升级ntpd服务_服务器准备升级,小程序将暂停使用
  7. C++中的IPv6网络程序设计
  8. sip中的100trying到底有啥用
  9. WinCE中命令行工具cvrtbin简介
  10. 代码补全_AI加持,Kite增加智能代码补全功能:减少一半操作,实时补全