https://www.codechef.com/viewsolution/26866025
can anyone please tell me why this is not accepting? Although i passed all the test cases.
Two mistakes:

Range of int is only from 32767 to 32767. The constraints for the array elements in the problem are 100000. â€ślong intâ€ť should be sufficient for it.

You only test for one case. You have to consider k items from both sides of sorted array. For example, try this case:
5 4
1 1 1 1 9
Your program will divide this in groups as
(1, 1, 1, 1) and (9)
and give output of maxdiff as 94=5
The case you miss is
(9, 1, 1, 1) and (1)
Maxdiff is 121=11
You have to output max(5,11) that is the maximum value from the two answers.
I have updated your solution to work in the link below, but I encourage you to try it yourself first.
Hope I made it clear for you.
https://www.codechef.com/viewsolution/26866391
I guess you have made a mistake in your first point,
The range of int data type is from 2^31 to 2^31  1, and it would fit in the given constraints.
Oh sorry my bad. While practicing C during my FE days, it was 2 bytes for int. Now I mostly code in Python so wasnâ€™t sure about those.
No problem, everyone makes mistakes.