i tried a simple DP problem of codechef (link:
http://www.codechef.com/problems/SUMTRIAN).
I am getting correct results on my system but on submission i get
Runtime Error (NZEC).Plzz help.My code is as follows:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
/**
*
* @author abhishek khanna
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
PrintWriter pw=new PrintWriter(new
OutputStreamWriter(System.out));
short test=Short.parseShort(br.readLine());
short i;
String[] str=new String[100];
for(i=0;i<test;i++)
{
byte rows=Byte.parseByte(br.readLine());
byte capacity=(byte)(rows+1);
byte[][] arr=new byte[capacity][capacity];
short[][] sum=new short[capacity][capacity];
short totalsum,maxsum;
byte r,c;
byte first=Byte.parseByte(br.readLine());
arr[1][1]=first;
sum[1][1]=first;
totalsum=first;
for(r=2;r<=rows;r++)
{
str=br.readLine().split(" ");
for(c=1;c<=r;c++)
{
if(c==1)
{
maxsum=sum[r-1][1];
}
else if(c==r)
{
maxsum=sum[r-1][r-1];
}
else
{
if(sum[r-1][c]>sum[r-1][c-1])
{
maxsum=sum[r-1][c];
}
else
{
maxsum=sum[r-1][c-1];
}
}
arr[r][c]=Byte.parseByte(str[c-1]);
sum[r][c]=(short) (arr[r][c] + maxsum);
if(totalsum<sum[r][c])
{
totalsum=sum[r][c];
}
}
}
pw.println(totalsum);
}
pw.flush();
// TODO code application logic here
}
}