You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include<vector>
#include<algorithm>
#include<cmath>classSolution {
public:intminEatingSpeed(std::vector<int>& piles, int h) {
int left = 1;
int right = *max_element(piles.begin(), piles.end());
int result = right;
while (left <= right) {
int mid = left + (right - left) / 2;
if (canFinish(piles, h, mid)) {
result = mid;
right = mid - 1; // 더 작은 속도로 시도
} else {
left = mid + 1; // 더 큰 속도로 시도
}
}
return result;
}
private:boolcanFinish(const std::vector<int>& piles, int h, int k) {
longlong totalHours = 0;
for (int pile : piles) {
totalHours += (pile + k - 1) / k; // 올림 계산if (totalHours > h) {
returnfalse; // 이미 시간이 초과함
}
}
return totalHours <= h;
}
};
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: