I think you have unnecessarily complicated it, or otherwise, I have misunderstood the problem.
If you want to check if K operations can make the array non positive, consider subtracting B from everything K times. And then you want to check if you can reduce K more elements by (A-B) to make everything non positive. It should be simply O( N \log a[i]_{max} ) .
yep, you are correct
i kinda felt that there is a much simpler solution than binarysearching for x_i(number of times a is removed) but was too lazy to think about it
thanks a lot
int count = 0;
sort(int a[],int n){
int temp,i,j;
for(i=0;i<n-1;i++){
for(j=i;j<n;j++)
if(a[i]>a[j]){
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
subtract(int a[],int n,int b, int c){
count++;
a[n-1]=a[n-1]-b;
int i;
for(i=0;i<n-1;i++){
a[i]=a[i]-c;
}
}
int main(){
int i,j,n,k=0,b,c;
printf(“Enter size of array :”);
scanf("%d",&n);
int a[n];
printf(“Enter b which is big value”);
scanf("%d",&b);
printf(“Enter c which is small value”);
scanf("%d",&c);
for(i=0;i<n;i++){
printf(“Enter elements :”);
scanf("%d",&a[i]);
}
while(k==0){
k=1;
for(i=0;i<n;i++){
if(a[i]>-1){
k=0;
}
}
sort(a,n);
subtract(a,n,b,c);
}
printf("%d",count-1);
}