Getting TLE in Modified LIS

my code https://ide.codingblocks.com/s/38262
ques link https://hack.codingblocks.com/contests/c/547/1147

this code works in o(n^2) therefore giving TLE. How to prevent the TLE. I have applied similar approach of that of LIS

somebody please tell how to avoid TLE in this

So , as the constraint is so large you should do this in <=O(nlogn) .
You can use binary search .
Just follow this link , you will understand