MULTHREE question giving wrong answer in codechef ide

my code with solution with proper comments and algo
this gives correct answer in my ide and in codechef if check via manual input.
But not accepting the answer.
tested all corner cases including when k==2;