MINIONS - Editorial

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 :slight_smile:

complexity O(nlogn)
Nice Approach @tihorsharma… got Ac in java
https://www.codechef.com/viewsolution/18943916

No problem :slight_smile: @vijju123

1 Like

Thank you :slight_smile:

1 Like

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.

1 Like

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 :slight_smile:

Here is my recursive implementation of the testers solution.
https://www.codechef.com/viewsolution/19229847

Good job dear. Hope you liked the editorial :slight_smile: