fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Main
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. int n;
  10. Scanner in = new Scanner(System.in);
  11. n = in.nextInt();
  12. int[] dp = new int[n + 1];
  13. for(int i = 1; i <= n; ++i){
  14. dp[i] = in.nextInt();
  15. }
  16. dp[1] = -1;
  17. for(int i = 3; i<=n; ++i){
  18. dp[i] = dp[i] + Math.max(dp[i-2], dp[i-3]);
  19. }
  20. System.out.println(dp[n]);
  21. }
  22. }
Success #stdin #stdout 0.07s 2184192KB
stdin
2
0 0
stdout
0