2d array question

Hello Please help me in solving this question.

The contest is over.

I am not able to figure out the approach

Question # 1
How to attempt?
Question :
Annual Day
On the occasion of annual day in school, the principal of the school decides that he will
distribute chocolates to students. The principle orders the students to stand in a queue and
the teachers have four types of chocolates. He wants to distribute chocolates in such a
manner that neighbouring students will not receive the same chocolate.
If ith student receives type-2 chocolate then, (i-1 and (i+1)th will not receive type-2
chocolates. The principle wants to know the minimum money needed to distribute the
chocolate. It is not necessary that chocolates of the same type are equal in price.
Input Specification
input1: Number of students.
input2: A 2-0 array (i x j) with i=input1 and j=4, representing the money
needed for giving j-type of chocolate to ith student.
Output Specification

Well just use simple dynamic programming, dp[i][j] denotes minimum cost for distributing chocolates to first i students and i^{th} student receives the j^{th} chocolate. Transitions would be O(1) since you need prefix max and suffix max of the previous(i-1) state.

If anyone get the code, please write it down here.