Skip to content

Commit

Permalink
Create PriyankaandToys.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnabBir authored Jan 23, 2018
1 parent e2dede4 commit dd13724
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions PriyankaandToys.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <bits/stdc++.h>

using namespace std;

int toys(vector <int> w) {
sort(w.begin(), w.end());
int curr = w[0], count = 1;
for(int i = 0; i < w.size(); ++i){
if(curr <= w[i] && w[i] <= (curr+4)) continue;
else{
++count;
curr = w[i];
}
}
return count;
}

int main() {
int n;
cin >> n;
vector<int> w(n);
for(int w_i = 0; w_i < n; w_i++){
cin >> w[w_i];
}
int result = toys(w);
cout << result << endl;
return 0;
}
Priyanka and Toys

0 comments on commit dd13724

Please sign in to comment.