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