-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheko.cpp
52 lines (43 loc) · 827 Bytes
/
eko.cpp
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
42
43
44
45
46
47
48
49
50
51
52
// https://www.acmicpc.net/problem/2805
#include <bits/stdc++.h>
using namespace std;
void rec(int, int, int); // low, high, target
vector<int> v;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin>>n>>m;
v=vector<int>(n);
for (int i = 0; i<n; ++i) {
cin>>v[i];
}
sort(v.begin(),v.end());
rec(0,v.back(),m);
return 0;
}
void rec(int low, int high, int target)
{
if (low>high) {
cout << high;
return;
}
int mid = (low+high)/2;
long long total = 0;
for (int t : v) {
if (t>mid) {
total+=t-mid;
}
}
if (total==target) {
cout << mid;
return;
}
else if (total>target) {
rec(mid+1,high,target);
}
else {
rec(0,mid-1,target);
}
}