#include<bits/stdc++.h>
int maxEle(vector<int>& arr){
    int n=arr.size();
    int maxi=INT_MIN;
    for(int i=0;i<n;i++){
        maxi=max(maxi,arr[i]);
    }
    return maxi;
}
int calculateTotalHours(vector<int>& arr,int bananaPerHour ,int h){
    int n=arr.size();
    int totalHour=0;
    for(int i=0;i<n;i++){
        totalHour+=ceil((double)(arr[i])/(double)(bananaPerHour));
        //to avoid overflow
        if(totalHour > h) break;
    }
    return totalHour;
}
int minimumRateToEatBananas(vector<int> arr, int h) {
    int low=1;
    int high=maxEle(arr);

    while(low<=high){
        int mid=(low+high)/2;
        int totalH=calculateTotalHours(arr, mid , h);

        if(totalH <= h) {
            high=mid-1;
        }
        else{
            low=mid+1;
        }
    }
    return low;
}