I am getting wrong answer for test case 4. I am unable to find the error. I have used the functions:
binarySearchSt-returns the element equal to or less than the key
binarySearchEn-returns the element equal to or greater than the key
For every contest, I am finding the optimal v and w and then I am checking if this combination of v and w yields the minimum time.
Code:
#include<bits/stdc++.h>using namespace std;int binSearchSt(int a[],int len,int key){int l=0,h=len-1;while(l<=h){int mid=l+(h-l)/2;if(a[mid]==key)return a[mid];else if(l==h)if(mid!=0)return a[mid-1]; else return a[mid];else if(key<a[mid]){h=mid;}else l=mid+1;}
Read more… (69 words)