https://programmers.co.kr/learn/courses/30/lessons/64062
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int> stones, int k) {
int answer = 0;
int low = 0;
int high = *max_element(stones.begin(),stones.end());
while(low < high){
int mid = (low + high)/2;
int count = 0;
int max_count = 0;
for(int k=0; k<stones.size(); k++){
int tmp = stones[k] - mid;
if(tmp <= 0){
count ++;
}
else{
max_count = max(count,max_count);
count = 0;
}
}
max_count = max(count,max_count);
if(max_count >=k){
high = mid;
}
else{
low = mid+1;
}
}
return low;
}
'프로그래머스' 카테고리의 다른 글
N으로 표현 C++ (0) | 2022.01.23 |
---|---|
거리두기 확인하기 C++ (0) | 2021.12.03 |
도둑질 C++ (0) | 2021.10.06 |
셔틀버스 C++ (0) | 2021.10.03 |
다단계 칫솔 C++ (0) | 2021.10.03 |