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;
  6. for(int i=0;i<num;i++){
  7. w[weight[i]]++;
  8. }
  9. int ans=0;
  10. for(int i=0;i<num;i++){
  11. count=0;
  12. if(w[i]%3==0){
  13. count=w[i]/3;
  14. }
  15. else{
  16. count+=w[i]/3+1;
  17. }
  18. ans=ans+count;
  19. }
  20. return ans;
  21.  
  22. }
  23.  
  24. int main() {
  25. // your code goes here
  26. int n;
  27. cin>>n;
  28. int packageWeight[n];
  29. for(int i=0;i<n;i++){
  30. cin>>packageWeight[i];
  31. }
  32. cout<<"the minimum number of trips are:"<<trips(packageWeight,n);
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5316KB
stdin
7
1 8 5 8 5 1 1
stdout
the minimum number of trips are:2