It is getting solved greedily but test case are not passing

https://ide.codingblocks.com/s/241130… plz help