Help with approach

prob: https://hack.codingblocks.com/app/contests/2022/918/problem
sol: https://ide.codingblocks.com/s/416533

please check the code and tell what is wrong

see this corrected code: