fork(1) download
  1. import java.io.BufferedReader;
  2. import java.io.BufferedWriter;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.io.OutputStreamWriter;
  6. import java.util.Scanner;
  7. class FitToPlay
  8. {
  9. public static void main(String[] args) throws NumberFormatException, IOException {
  10. Scanner sc=new Scanner(System.in);
  11. int t=sc.nextInt();
  12. int n;
  13. int preBest=Integer.MIN_VALUE;
  14. int min;
  15. int prev,a,b,i=0;
  16. int temp;
  17. boolean isfound=false;
  18.  
  19. while(t-->0)
  20. {
  21. i=0;
  22. isfound=false;
  23. n=sc.nextInt();
  24. preBest=Integer.MIN_VALUE;
  25. if(n==1)
  26. {
  27. sc.nextInt();
  28. wr.write("UNFIT");
  29. wr.newLine();
  30. continue;
  31. }
  32. else
  33. {
  34. a=sc.nextInt();
  35. b=sc.nextInt();
  36. if(b>a)
  37. {
  38. isfound=true;
  39. min=a;
  40. preBest=b-a;
  41. }
  42. else
  43. min=b;
  44. i+=2;
  45. prev=b;
  46. while(i<n)
  47. {
  48. a=sc.nextInt();
  49. if(a>prev)
  50. {
  51. isfound=true;
  52. temp=a-min;
  53. if(temp>preBest)
  54. preBest=temp;
  55. }
  56. else
  57. {
  58. if(a<min)
  59. min=a;
  60. }
  61. ++i;
  62. prev=a;
  63. }
  64. }
  65. if(isfound)
  66. {
  67. wr.write(Integer.toString(preBest));
  68. wr.newLine();
  69. }
  70. else
  71. {
  72. wr.write("UNFIT");
  73. wr.newLine();
  74. }
  75. }
  76. wr.close();
  77. }
  78.  
  79. }
Runtime error #stdin #stdout 0.02s 245632KB
stdin
Standard input is empty
stdout
Standard output is empty