Created
February 9, 2020 08:45
백준 문제풀이
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
// 이분탐색 | |
// 가능한 최대 높이 | |
const int INF = 1e9; | |
int N, M, A[1000003], mid; | |
long long sum; | |
int main(){ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL); | |
cin >> N >> M; | |
for (int i = 0; i < N; ++i) cin >> A[i]; | |
int lo = 0; | |
int hi = INF; | |
// 알맞은 높이 찾기 | |
while(lo+1 < hi){ | |
mid = (lo+hi)/2; | |
sum = 0; | |
for (int i =0 ; i < N; ++i) | |
if(A[i]>mid) | |
sum += A[i] - mid; | |
if(sum >= M) | |
lo = mid; | |
else | |
hi = mid; | |
} | |
cout << lo << '\n'; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment