Hi,
I have tested my solution for the SUMTRIAN problem on Ideone and Eclipse and it runs fine. However on SPOJ it gives and NZEC error again and again
Please help me to fix this. I am having the same problem with another java solution for some other problem. If this goes on I guess I might have to quit submitting Java solutions
The problem was to calculate the biggest sum of numbers in a path in a triangle of numbers (with some other constraints) I followed a bottom-up approach.
https://www.spoj.pl/problems/SUMTRIAN/
Here is the code:
public class Main{
public static void main(String[] args){
java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
try{
int numTests = Integer.parseInt(br.readLine().trim());
for(int i=0;i<numTests;i++){
int numLines = Integer.parseInt(br.readLine().trim());
int mat[][] = new int[numLines][];
for(int j=0;j<numLines;j++){
mat[j] = new int[j+1];
String line = br.readLine().trim();
String[] numArray = line.split("\\s+");
for(int k=0;k<numArray.length;k++){
mat[j][k] = Integer.parseInt(numArray[k]);
}
}
for(int a=numLines-1;a > 0;a--){
for(int b=0;b<a;b++){
if(mat[a][b] > mat[a][b+1]){
mat[a-1][b]+=mat[a][b];
}else{
mat[a-1][b]+=mat[a][b+1];
}
}
}
System.out.println(mat[0][0]);
}
}catch(Exception e){}
}
}