LIS Modified problem

I am unable to think of NlogN solution of this problem.the standard solution will not get accepted.
Please help me with some hints on how to approach the problem!

@abhir26 Please try the problem using fenwick tree(BIT), Think in terms of mapping the numbers and finding the sum for each index using BIT. Expected complexity for each test case will be around n log n
Or
Firstly pair banakr sort krlo all pairs ko , fir simple lis laga do jo second array bani usme…
lis can also be done in onlogn try that.