-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1201C.cpp
More file actions
43 lines (39 loc) · 806 Bytes
/
1201C.cpp
File metadata and controls
43 lines (39 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "bits/stdc++.h"
using lli = long long int;
using namespace std;
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define inarr(a,n) for(int i = 0; i < n; ++i) cin >> a[i];
#ifndef ONLINE_JUDGE
#define db(x) cerr << #x <<" = " << n << "\n";
#else
#define db(...)
#endif
//
lli a[200005];
void solve(){
int n;lli k;cin >> n >> k;
inarr(a,n);
sort(a,a+n);
lli sum=0;
int q = n / 2;
for (int i=q;i<n;i++)sum+=a[i];
int p = n - 1;
while (p > q && sum + k < a[p] * (p - q + 1)){
sum -= a[p];
p--;
}
a[q] = a[p];
k -= a[p] * (p - q + 1) - sum;
lli t = p - q + 1;
a[q] += k / t;
cout << a[q];
}
int main(){
cin.tie(nullptr);cout.tie(nullptr);ios::sync_with_stdio(false);
int t = 1;
// cin >> t;
while(t--){
solve();
}
}