We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
why is this TLE? I am using binary search and the last for loop -- couldn't possibly go too much back.
longminTime(vector<long>machines,longgoal){//binary search// check if sum of machines = goal or < or >intn=machines.size();longfastest=*min_element(machines.begin(),machines.end());longlow=0,high=goal*fastest;longmid=(low+high)/2;longsum=0;while(high>=low){sum=0;for(inti=0;i<n;i++){sum+=(mid/machines[i]);}if(sum==goal)break;elseif(sum>goal){high=mid;}else{low=mid;}mid=(low+high)/2;}intnum=mid;while(sum==goal){num--;sum=0;for(inti=0;i<n;i++){sum+=(num/machines[i]);}if(sum!=goal){num++;break;}}returnnum;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Time Required
You are viewing a single comment's thread. Return to all comments →
why is this TLE? I am using binary search and the last for loop -- couldn't possibly go too much back.