I am a beginner, Please somebody help me in this question,

Can somebody tell me how to solve this problem (Contest Page | CodeChef) and what is the mistake in my code?

#include <iostream>

using namespace std;

int main() {
    long int n;
    cin>>n;
    int arr[n],ans[n];
    
    for(int i = 0; i<n; i++){
        cin>>arr[i];
    }
    
    
    ans[0] = arr[0];
    ans[1] = arr[n-1];
    for(int i = n-1,j=2; i>1; i--,j++){
       ans[j] = arr[i-1] + min(ans[j-1],ans[j-2]);
   }
    
    cout<<ans[n-1];
}