Help in Two Flower

Can someone help me to figure out how do i Improve my code? i am only getting TLE in Two Cases.
link

Editorial is out see it. and close this question