fork download
  1. import java.util.*;
  2.  
  3. class OldSchoolHero {
  4. public static List<Integer> minOperations(int T, List<int[]> testCases) {
  5. List<Integer> results = new ArrayList<>();
  6.  
  7. for (int t = 0; t < T; t++) {
  8. int[] boxes = testCases.get(t);
  9. int minValue = Arrays.stream(boxes).min().getAsInt();
  10. int totalOps = Integer.MAX_VALUE;
  11.  
  12. Arrays.sort(boxes);
  13. int ans=0,add=0;
  14. for(int i=1;i<boxes.length;i++)
  15. {
  16. int diff = boxes[i] - boxes[i - 1] + add;
  17. add += diff;
  18. int temp=0;
  19. ans+=(diff/5);
  20. temp=diff%5;
  21. ans+=(temp/2);
  22. ans+=(temp%2);
  23. // System.out.println(ans+" "+i);
  24. }
  25.  
  26. results.add(ans);
  27.  
  28. }
  29.  
  30. return results;
  31. }
  32.  
  33. public static void main(String[] args) {
  34. Scanner sc = new Scanner(System.in);
  35.  
  36. int T = sc.nextInt();
  37. List<int[]> testCases = new ArrayList<>();
  38.  
  39. for (int i = 0; i < T; i++) {
  40. int M = sc.nextInt();
  41. int[] boxes = new int[M];
  42. for (int j = 0; j < M; j++) {
  43. boxes[j] = sc.nextInt();
  44. }
  45. testCases.add(boxes);
  46. }
  47.  
  48. List<Integer> results = minOperations(T, testCases);
  49. for (int res : results) {
  50. System.out.println(res);
  51. }
  52.  
  53. sc.close();
  54. }
  55. }
  56.  
Success #stdin #stdout 0.11s 56764KB
stdin
1
3
7 10 12
stdout
3