The Question is -> https://mirror.codeforces.com/contest/2013/problem/D
My approach is as follows :
If someone could help me out it would be greatly appreciated.
My submission for ref -> https://mirror.codeforces.com/contest/2013/submission/297131396
Thanks!!