I got the logic except that I have just one problem.

The answer what everybody(below accepted coded) is printing is just the final index(all final indexes of all dimensions) of 3-D dp array i.e. just that one value.

But isn't it just the length of longest decreasing subsequence after considering all pos of the array.

Should it have been that

int res=INT_MAX;

res=max(res, dp[n-1][i][i]+dp[n-1][i][j]);

where i and j run for the entire length of the dp array.

Because the problem asks for the total no of rooms encountered by both the people.

Here just returning the longest decreasing sequence means only those rooms encountered by catwoman.

Please help here. I am seriously puzzled by this tho...