July lunchtime, 2019 dp problem plz help

here is the code plz help me in finding why this program is not working

import java.util.*;

public class Main{
public static void main (String args[]){
try{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
int ht=t;
long ansf[]=new long[t];
while(ht–>0){
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
long h[]=new long[n];
long ans=a[0];
h[0]=a[0];
if(n>=2){
h[1]=Math.max(a[0]*1+a[1]2,a[1]1+a[0]2);
}
for(int i=2;i<n;i++){
ans=Math.max(a[i]
(i+1)+h[i-1],a[i]
(i)+a[i-1]
(i+1)+h[i-2]);
h[i]=ans;
}
ansf[t-ht-1]=ans;
}

        for(int i=0;i<t;i++){
            System.out.println(ansf[i]);
        }
    }catch(Exception e){
        e.printStackTrace();
    }
}

}

1 Like

Mention the problem
It’s difficult to understand your code

Swapping question i am guessing…

https://www.codechef.com/viewsolution/25477068
Check my solution…logically i feel your answer is correct but you are missing something important.
I have solved in C++