fork download
  1. import java.io.*;
  2.  
  3.  
  4. class SumInTriangle {
  5. public static void main(String args[]) throws IOException{
  6. int[][] arr=new int[100][100];
  7.  
  8. int testcases =Integer.parseInt(br.readLine());
  9.  
  10. while(testcases>0)
  11. {
  12.  
  13. int n = Integer.parseInt(br.readLine());
  14. for(int i=0;i<n;i++)
  15. {
  16. for(int j=0;j<=i;j++)
  17. arr[i][j]= Integer.parseInt(br.readLine());
  18. }
  19. for(int i=n-2;i>=0;i--)
  20. {
  21. for(int j=0;j<=i;j++)
  22. {
  23. arr[i][j]+=arr[i+1][j]>arr[i+1][j+1]?arr[i+1][j]:arr[i+1][j+1];
  24. }
  25. }
  26. System.out.printf("%d\n",arr[0][0]);
  27. testcases--;
  28. }
  29.  
  30.  
  31. }
  32.  
  33. }
Runtime error #stdin #stdout #stderr 0.07s 380160KB
stdin
2
3
1
2 1
1 2 3
4 
1 
1 2 
4 1 2
2 3 1 1 
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.NumberFormatException: For input string: "2 1"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:492)
	at java.lang.Integer.parseInt(Integer.java:527)
	at SumInTriangle.main(Main.java:18)