fork(2) download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5. typedef unsigned long long int ul;
  6.  
  7. void reset(int grades[6]){
  8. for(int i=0;i<6;i++)
  9. grades[i]=0;
  10. }
  11.  
  12. ul average(int grades[6], int k,int n){
  13. ul res=0;
  14. for(int i=0;i<6;i++)
  15. res+=(ul)grades[i]*(ul)pow(i+1,k);
  16. return res/n;
  17. }
  18. int bestAverage(int grades[6],int n){
  19. int k=1;
  20. bool underFour = false, aboveFour = false;
  21. for(int i=0;i<6;i++){
  22. if (i<3 && grades[i]>0)
  23. underFour = true;
  24. if (i>3 && grades[i]>0)
  25. aboveFour = true;
  26. }
  27. if (underFour == true && aboveFour == false)
  28. return -1;
  29. else {
  30. while (average(grades,k,n)<(ul)pow(4,k)){
  31. k++;
  32. }
  33. return k;
  34. }
  35. }
  36. int main()
  37. {
  38. int grades[6],t,n,number;
  39. cin>>t;
  40. for(int i=0;i<t;i++){
  41. reset(grades);
  42. cin>>n;
  43. if (n!=0){
  44. for(int j=0;j<n;j++){
  45. cin>>number;
  46. grades[number-1]++;
  47. }
  48. cout<<bestAverage(grades,n)<<endl;
  49. } else
  50. cout<<-1<<endl;
  51. }
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0.01s 5524KB
stdin
6
5
1 2 3 1 3
4
1 2 3 5
5
1 1 5 1 1
2
4 2
7
4 4 4 3 1 3 1
18
3 2 2 5 5 2 3 1 3 5 4 1 3 6 5 6 1 3
stdout
-1
6
8
-1
-1
3