PRATA (Spoj) Problem

Is my logic correct I am not getting the correct answer
tell your logic also