fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int trips(int weight[],int num){
  4. unordered_map<int,int>w;
  5. int count=0;
  6. for(int i=0;i<num;i++){
  7. w[weight[i]]++;
  8. }
  9. for(int i=0;i<num;i++){
  10. if(w[weight[i]]%3==0){
  11. count++;
  12. }
  13. else{
  14. count=w[i]/3+1;
  15. }
  16. }
  17. return count;
  18.  
  19. }
  20.  
  21. int main() {
  22. // your code goes here
  23. int n;
  24. cin>>n;
  25. int packageWeight[n];
  26. for(int i=0;i<n;i++){
  27. cin>>packageWeight[i];
  28. }
  29. cout<<"the minimum number of trips are:"<<trips(packageWeight,n);
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5288KB
stdin
7
1 8 5 8 5 1 1
stdout
the minimum number of trips are:3