fork download
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.StringTokenizer;
  5.  
  6. public class Main {
  7. public static void main(String[] args) throws IOException {
  8. StringBuilder sb = new StringBuilder();
  9. int n = Integer.parseInt(br.readLine());
  10. for(int i=0; i<n; i++){
  11. int m = Integer.parseInt(br.readLine());
  12. int sticker[][] = new int[2][m];
  13. token = new StringTokenizer(br.readLine());
  14. token2 = new StringTokenizer(br.readLine());
  15. for(int j=0; j<m; j++){
  16. sticker[0][j] = Integer.parseInt(token.nextToken());
  17. sticker[1][j] = Integer.parseInt(token2.nextToken());
  18. }
  19. if(m == 1){
  20. sb.append(Math.max(sticker[0][0], sticker[1][0]));
  21. continue;
  22. }
  23. sticker[0][1] += sticker[1][0];
  24. sticker[1][1] += sticker[0][0];
  25. for(int k=2; k<m && m>2; k++){
  26. sticker[0][k] += Math.max(sticker[1][k-1], sticker[1][k-2]);
  27. sticker[1][k] += Math.max(sticker[0][k-1], sticker[0][k-2]);
  28. }
  29. sb.append(Math.max(sticker[0][m-1], sticker[1][m-1])).append("\n");
  30. }
  31. System.out.print(sb);
  32. }
  33. }
  34.  
Success #stdin #stdout 0.08s 55040KB
stdin
5
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
stdout
11111