PRATA Spoj Problem

Is my logic correct I am not getting the correct answer