Advertisement
Guest User

Priyanka and Toys

a guest
Oct 17th, 2016
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. int cost(const vector<int>& weights) {
  2.     if (weights.empty()) {
  3.         return 0;
  4.     }
  5.    
  6.     vector<bool> allWeights(10000);
  7.     for (int w : weights) {
  8.         allWeights[w] = true;
  9.     }
  10.    
  11.     int count = 0;
  12.     int i = 0;
  13.     while (i < allWeights.size()) {
  14.         if (allWeights[i]) {
  15.             ++count;
  16.             i += 5;
  17.         } else {
  18.             ++i;
  19.         }
  20.     }
  21.    
  22.     return count;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement