is there any greedy solution possible for this problem
https://mirror.codeforces.com/problemset/problem/1223/C