fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int[] A = {4, 2, 11, -2, 1};
  13. int[] leftMaxes = new int[A.length - 1];
  14. int[] rightMaxes = new int[A.length - 1];
  15.  
  16. leftMaxes[0] = A[0];
  17. for (int i = 1; i < A.length - 1; ++i) {
  18. leftMaxes[i] = Math.max(leftMaxes[i-1], A[i]);
  19. }
  20.  
  21. rightMaxes[A.length - 2] = A[A.length - 1];
  22. for (int i = A.length - 3; i >= 0; --i) {
  23. rightMaxes[i] = Math.max(rightMaxes[i+1], A[i+1]);
  24. }
  25.  
  26. for (int i = 0; i < A.length - 1; ++i) {
  27. System.out.printf("%d: %d %d%n", i, leftMaxes[i], rightMaxes[i]);
  28. }
  29. }
  30. }
Success #stdin #stdout 0.13s 320576KB
stdin
Standard input is empty
stdout
0: 4 11
1: 4 11
2: 11 1
3: 11 1