-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2512_예산.cpp
69 lines (51 loc) · 854 Bytes
/
2512_예산.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> v;
int N, M;
int check = 0;
long long calcBudget(int n) {
long long sum = 0;
for (int i = 0; i < N; i++) {
if (v[i] <= n) {
check++;
sum += v[i];
}
else {
sum += n;
}
}
return sum;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int start, end, mid;
int result = 0;
cin >> N;
for (int i = 0; i < N; i++) {
int temp;
cin >> temp;
v.push_back(temp);
}
sort(v.begin(), v.end());
cin >> M;
start = 0;
end = v.back();
while (start <= end) {
mid = (start + end) / 2;
check = 0;
long long budget = calcBudget(mid);
if (budget <= M) {
start = mid + 1;
result = max(result, mid);
}
else {
end = mid - 1;
}
}
cout << result;
return 0;
}