WA in Cook Off 54 : Abhijeet and rectangles

I understood the editorial to the question but why does my approach not work?

My approach-

Sort the lengths and breadth in two different lists and maintain pointers to the first element of each of them. Let’s call these two lists l and b, and the two pointers i and j for our convenience.

Let A1 = l[i] * b[j+1] and A2 = l[i+1] * b[j]

(i.e. A1 = smallest length * second smallest breadth; A2 = second smallest length * smallest breadth)

If A1 < A2 remove the rectangle with shortest length and mark it as removed else remove rectangle with shortest breadth and mark that as removed.
My code

Any help will be appreciated!

What answer are you getting for this case… Ans should be 10!!

3 2
2 3
3 3
1 10
1 Like

I am getting 9, the code removes the wrong rectangle. Got my mistake! Thanks!