Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <vector>
- using namespace std;
- int fun(int n, int limit, vector<int>& v){
- int low =1;
- int high=v.size();
- int ans=0;
- while(low<high){
- int mid = low+(high-low)/2;
- int idx=0;
- float temp= (limit*1.0)/mid;
- int flag=0;
- // cout<<"mid "<<mid<<" "<<temp<<endl;
- while(idx<v.size()){
- int c=0;
- while((1.0*v[idx])>temp){
- idx++;
- c++;
- // cout<<c<<endl;
- }
- if(c>=mid){
- flag=1;
- break;
- }
- idx++;
- }
- if(flag){
- ans=max(ans,mid);
- low=mid+1;
- }
- else{
- high=mid-1;
- }
- // cout<<low<<" " <<high<<endl;
- }
- cout<<ans;
- if(ans==0){
- return -1;
- }
- return ans;
- }
- int main()
- {
- vector<int> v = {2};
- fun(1,7,v);
- }
Advertisement
Add Comment
Please, Sign In to add comment