Clarification needed in Chef and strange matrix (chefbm)

please clarify

As per constraints 1 ≤ n, m. if n is 1 only one column. how cost can be calculated through a(i)(j) - a(i)(j - 1).

As the cost of a movement is a(i)(j) - a(i)(j - 1).

I am getting wrong answer even if my output is exactly matched.


check the problem statement clearly.
n is for row and m elements present in that row.
It is ongoing contest so cant discuss strategy just can help you to concentrate on this statement…

For each row he tries to move from the last element (with number m) to the first one (with the number 1)

If Chef can move from the last element of the row to the first one, then the answer is the total cost of all the movements

This is what i can do right now read it twice you would definitely get it!

Good Luck :slight_smile:


Thank you for replying on my query and sorry for type. yes that is m which I wanted to point out, if there is only one element in a particular row i.e. is m=1.
that means our first element is the last element but its value may not be 1 because we can increased its value through a p command.
Don’t you think In this case to calculate this case either the cost would be 0 because of statement he tries to move from the last element (with number m) to the first one .
but if we say the cost should be a(i)(j) - a(i)(j-1) then this will throw index out of bound exception.

1 Like

Array starts with zero.

Incase of 1 ≤ i ≤ n, 1 ≤ j ≤ m
Initialize a[0][0]=0;

i don’t get it @tech_boy, it doesn’t make sense.
did u get a successful submission?!