Doubt in MAXAND18 (June LunchTime)

Problem-Click Here
Solution-Solution with comments for explaination

I am only getting AC in Subtask 2 Task #1 and rest of all WA.
I have tried many custom test cases which worked correctly.
Can Anybody Point out where i am going wrong?
Thanks In Advance!

[EDIT]-This Problem is Solved Now!Thanks Everyone

@zephxr Refer this - My solution

There seems to be a problem with your customsort function. Since you are accessing the elements from the rear after sorting V, I believe you should sort the bits in the opposite order to ensure minimum X.

Yes i also realized that my algorithm seems correct but main problem is with customsort.
Before seeing your solution, can you guide how can i change my customsort function :slightly_smiling_face:

Since you are accessing the elements in reverse order, x.second should be sorted in decreasing order rather than increasing order otherwise, the largest value of x.second will be accessed first.

yes , this i know friend,just i am stuck with implementation.

in the condition
if(a.first == b.first) return a.second < b.second
change it to >

1 Like
bool customsort(const pair<int,int>&a,const pair<int,int>&b)
{
  if(a.first==b.first)
  {
    return a.second>b.second;
  }
  return a.first<b.first;
}
1 Like

Thanks for the help @sebastian @anon11076894
I added two more else if’s in customsort function which gave me AC.
My AC Solution-Click Here

@sebastian Your Solution too worked, Thank You So Much!

Thanks @anon11076894 !

bool c__(pair<long long int, int> a, pair<long long int, int> b) {
	if (a.first > b.first) return true;
	if (a.first == b.first && a.second < b.second) return true;
	return false;
}

this had worked for me fine

1 Like