-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj2512.cpp
More file actions
52 lines (47 loc) · 952 Bytes
/
boj2512.cpp
File metadata and controls
52 lines (47 loc) · 952 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
42
43
44
45
46
47
48
49
50
51
52
// 5분 38초
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <set>
#include <queue>
using namespace std;
using p = pair<int, int>;
using ll = long long;
const int MAX = 10e+6;
const int INF = 0x66554433;
inline void Quick_IO(){
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
int arr[10005];
int main(){
Quick_IO();
int N, M;
cin>>N;
for (int i = 0; i < N; ++i) {
cin>>arr[i];
}
cin>>M;
int lo = 0;
int hi = *max_element(arr, arr+N);
int answer = -INF;
while(lo<=hi){
int mid = (lo+hi)/2;
ll temp = 0;
for (int i = 0; i < N; ++i) {
temp += min(mid, arr[i]);
}
if(temp<=M){
answer = max(mid, answer);
lo = mid+1;
}else{
hi = mid-1;
}
}
cout<<answer<<"\n";
return 0;
}