You want fit in as many balls in a bag of weight W. What do you chose? Lighter balls or heavy balls? We only have to maximise number of balls in bag.
Then apply the logic to current scenario. Thanks @tihorsharma123 for helping me
You want fit in as many balls in a bag of weight W. What do you chose? Lighter balls or heavy balls? We only have to maximise number of balls in bag.
Then apply the logic to current scenario. Thanks @tihorsharma123 for helping me
complexity O(nlogn)
Nice Approach @tihorsharma… got Ac in java
https://www.codechef.com/viewsolution/18943916
Thank you
i do agree with you that it would be so appreciable if setter has added comments in his code , that would make it lot easier.
int mainquery(ll x,ll y)
{
int lo=0;
int hi=n-1;
int k=0;
int ans=0;
while(lo<=hi)
{
int mid=(lo+hi)/2;
k=query1(1,0,n-1,0,mid); // the number of element
ll val=query2(1,0,n-1,0,mid); // the sum in given range
if((x*1LL*(k+1)*1LL)>=(val+y))
{
ans=k+1;
lo=mid+1;
}
else
hi=mid-1;
}
return ans;
}
its the query function i wrote with binary search , its passing the case in testcase bank but getting WA , help me debug
All the test cases were maximal, so official cases wont help. I will try to add few more cases.
issue solved i was using int instead of long long .
@vijju123 Tester’s code gives wrong answer for following case
1
12
10 100
12 1
12 1
12 1
12 1
12 1
12 1
12 1
12 1
12 1
12 1
12 100000000
correct answer is 11 whereas Tester’s code outputs 10.
Will inform him that his solution got hacked xD. Nice job. The setter’s solution (used to make TC) is correct. The idea is also correct, he made a minor bug in implementation, so no major problem. Thanks
Here is my recursive implementation of the testers solution.
https://www.codechef.com/viewsolution/19229847
Good job dear. Hope you liked the editorial