Question
Nest Craze
In a quaint village, artisans craft envelopes of varying sizes for hidden notes. Each envelope has a width and height, and one can fit inside another only if both its width and height are greater.
Kiera, captivated by this custom, seeks the longest sequence of envelopes that can be nested without rotation.
Find the maximum number of envelopes she can stack.
Input
The first line of the input contains a two space separated integers m and n, representing the size(rows and columns) of the 2D array envelopes[][], where n is always equal to 2.
The next m line of the input contains 2 integers each, representing elements of the array.
The next m line of the input contains 2 integers each, representing elements of the array.
Output
Print the maximum number of envelopes she can stack.
Example
Sample Input
4 2
5 4
6 4
6 7
2 3
Sample Output
3
Explanation
The maximum number of envelopes that can be stacked is 3 ([2,3] => [5,4] => [6,7]).
4 2
5 4
6 4
6 7
2 3
Sample Output
3
Explanation
The maximum number of envelopes that can be stacked is 3 ([2,3] => [5,4] => [6,7]).