思路
sort,然后从中点向后维护。
代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5+10;
int a[N], n, k;
signed main(){
cin>>n>>k;
for(int i = 1; i <= n; i++) cin>>a[i];
sort(a+1, a+1+n);
int mid = n / 2+1;
int tmp = 0;
int len;
for(int i = mid; i < n; i++){
len = i - mid + 1;
int w = a[i+1]-a[i];
if(k/len <= w){
cout<<a[i]+k/len<<endl;
goto done;
}
k -= w*len;
}
len = n - mid + 1;
cout<<a[n]+(k/len)<<endl;
done:;
return 0;
}
都是大佬啊