Find error
Find error
#include<bits/stdc++.h>
using namespace std;
class Solution{
public:
bool isPossible(vector<int>ank,int n,int mid)
{
int count=0;
for(int i=0;i<rank.size())
{
int val= (-1 + sqrt(1+(8*mid)/rank[i]))/2;
count+=val;
}
return count>=n;
}
int findMinTime(int N, vector<int>&A, int L){
int low=*min_element(A.end()),high=1000000;
int ans=high;
while(low<=high)
{
int mid=low+(high)/2;
if(isPossible(A,mid))
{
ans=mid;
high=mid;
}
else
low=mid;
}
return ans;
}
};
int main()
{
int t;
cin>>t;
while(t--)
{
int l;
cin >> l;
vector<int>arr(l);
for(int i = 0; i < l; i++){
cin >> arr[i];
}
Solution ob;
int ans = ob.findMin(n, *arr, l);
cout << ans <<endl;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images