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. // Write any import statements here
  8.  
  9. class Solution {
  10.  
  11. public int getMinProblemCount(int N, int[] S) {
  12.  
  13. int ans = 0;
  14. boolean three_two = false;
  15. int [] points = {3,2,1};
  16. int [] frq = new int[4];
  17. int [] all_3_2_1 = new int[4];
  18. for(int s : S){
  19. int v = s;
  20. for(int p: points){
  21.  
  22. frq[p] = Math.max(v/p, frq[p]);
  23.  
  24. v = v - (v/p) * p;
  25. }
  26. }
  27. System.out.println(Arrays.toString(frq));
  28. int all = 0;
  29. if(frq[2] >= 1 && frq[1] >= 1 && frq[3] >= 2) ans--;
  30. for(int i : frq) {
  31. ans+=i;
  32. }
  33. return ans;
  34. }
  35.  
  36. public static void main(String [] args){
  37.  
  38. Solution sc = new Solution();
  39. System.out.println("Answer 1 = "+ sc.getMinProblemCount(5, new int[] {9,6,3,2,1}));
  40. System.out.println("Answer 2 = "+ sc.getMinProblemCount(11, new int[] {1,4,2,3,1,4,5,1,5,1,6}));
  41. }
  42. }
  43.  
Success #stdin #stdout 0.12s 55640KB
stdin
Standard input is empty
stdout
[0, 1, 1, 3]
Answer 1 = 4
[0, 1, 1, 2]
Answer 2 = 3