fork(1) download
  1. import java.util.*;
  2.  
  3. class Farida {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. int t = Integer.parseInt(sc.nextLine());
  7. for (int i = 1; i <= t; i++) {
  8. int n = Integer.parseInt(sc.nextLine());
  9. long sol = 0;
  10. if (n > 0) {
  11. String line = sc.nextLine();
  12. if (!line.equals("")) {
  13. String[] monsters_str = line.split(" ");
  14. long[] monsters = new long[n];
  15. for (int j = 0; j < n; j++) {
  16. monsters[j] = Long.parseLong(monsters_str[j]);
  17. }
  18. //Algorithm to solve problem: I solve from the smallest to the biggest problem, from the last monster to the first
  19.  
  20. for (int k = n-1; k >= 0; k--) {
  21. long s2 = 0;
  22. long s1 = 0;
  23. if (k+2 < n) {
  24. s2 = monsters[k+2];
  25. }
  26. if (k+1 < n) {
  27. s1 = monsters[k+1];
  28. }
  29. monsters[k] = Math.max(monsters[k]+s2,s1);
  30. }
  31. // En monsters[0] queda la solucion del problema
  32. sol = monsters[0];
  33. }
  34. }
  35. System.out.println("Case "+i+": "+sol);
  36.  
  37. }
  38. }
  39. }
Runtime error #stdin #stdout #stderr 0.14s 321088KB
stdin
2
5
1 2  3 4 5
1
10
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Long.parseLong(Long.java:601)
	at java.lang.Long.parseLong(Long.java:631)
	at Farida.main(Main.java:16)