This problem would have been a classical problem if the memory limits would not have been that tight. In the classical version we can use DP or the LCS with O(n^2) memory but this problem requires O(n) memory.
How to go about it?
I searched the solution of this problem online but found only codes and not the solution.
Note: There is no official syllabus for ZCO vs INOI vs IOITC. Syllabus for ZCO, INOI has been determined by looking at all the concepts covered in all ZCO, INOI problems since last 5 years. All the topics covered by ZCO, INOI are also in the Basic topics section of ICO online study material. Syllabus for IOITC is same as syllabus for IOI, since the training camp is training you for IOI. There is a higher focus on the topics mentioned in the Advanced topics specifically covered in ICO online study material. :)
The below tutorials are the best tutorials on the internet for each topic. If you find better tutorials for a particular topic, please share them with everyone.