fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. Scanner x = new Scanner(System.in);
  11. while(x.hasNext()){
  12. int n=x.nextInt();
  13. int[]y=new int[n];
  14. for(int i=0;i<n;i++){
  15. y[i]=x.nextInt();
  16.  
  17.  
  18. }
  19. int val=0;
  20. int max=0;
  21. for(int j=0;j<n-1;j++){
  22.  
  23. if(y[j]<y[j+1]){
  24.  
  25. val=y[j+1]-y[j];
  26. if(val>max){
  27.  
  28. max=val;
  29. }
  30. }
  31.  
  32. }
  33.  
  34. // your code goes here
  35. if(max==0){
  36. System.out.println(1);
  37.  
  38. }else{
  39.  
  40. System.out.println(max);
  41.  
  42. }
  43. }
  44. }
  45. }
Success #stdin #stdout 0.13s 49436KB
stdin
6
5 2 1 4 5 3
3
1 1 1
4
4 3 2 1
stdout
3
1
1