日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 1201C】Maximum Median(思维,水题)

發布時間:2023/12/10 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 1201C】Maximum Median(思维,水题) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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(思维,水题)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。