-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathc.cc
More file actions
36 lines (34 loc) · 664 Bytes
/
c.cc
File metadata and controls
36 lines (34 loc) · 664 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
// https://codeforces.com/contest/1201/problem/C
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll n, k;
cin >> n >> k;
vi a(n);
for (int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
int i = n / 2;
ll x = a[i++];
while (true) {
while (i < n && a[i] == x) i++;
if (i < n) {
ll p = a[i] - x;
ll q = i - n / 2;
if (p * q <= k) {
x = a[i];
k -= p * q;
} else {
x += k / q;
break;
}
} else {
x += k / (n - n / 2);
break;
}
}
cout << x << "\n";
}