Chef and Employment test **Note : * It is guaranteed that n+k is an odd number and also k < n. So it is obvious that the median will be a number having index number between 0 and n1. And also the median of the whole array will be at index (n+k)/2 . First of all sort the given array We have to add numbers such that we have the maximum medium . There can be two cases : (1) Adding numbers greater than the number at index (n+k)/2 . (2) Adding numbers less than the number at index (n+k)/2 . If we add numbers less than the number at index (n+k)/2 , it will shift that number away from the median and the new median will be a lesser number . So we should only add number greater than number at index (n+k)/2 . So the answer by default becomes the number at index (n+k)/2 in the original array. Chef and Weird Queries A simple observation is that b can't be greater than 700 so all the values of A , having , number of B values that satisfy the equation can be at max 700 even if there are a lot of possible values . So if the number of B that satisfy the equation for a particular A are greater than 700 , we only consider 700 pairs for that A . Building upon this , if y700 <=0 this means that there are no such values which for a particular A , have number of B >700 . So we only simply count the number of B for every value of A
else upto the square root of y700 , for all A , number of B are greater than 700 so we add them to our answer a=(long long int)(sqrt(y700));
And then from (long long int)(sqrt(y700))+1 until a^2 <=y , we individually add B for every value of A. for(long long int i=(a)+1;i*i<=y;i++) {
} asked 23 Oct '17, 00:38

@b123eginner don't use scanf with sync_with_stdio(false) answered 23 Oct '17, 02:33

@b123egineer check your code on following case https://ideone.com/7YzCvx answered 23 Oct '17, 18:14

Makes me feel good when I see some1 using register keyword. :D
Haha , It is ingrained in my muscle memory .