https://mirror.codeforces.com/contest/1792/problem/D
//At the bottom there is my submission.
https://mirror.codeforces.com/contest/1792/submission/190984642
can anyone help me in giving further ideas to optimize my implementation. If possible can anybody teach me how to tackle these kinds of problems with newer ideas(new concepts).