diff options
| author | Omar Magdy <omar.professional8777@gmail.com> | 2022-04-30 01:13:40 +0200 |
|---|---|---|
| committer | Omar Magdy <omar.professional8777@gmail.com> | 2022-04-30 01:13:40 +0200 |
| commit | a0d7b8320a8996eee0ed957b79c3a882f8b47146 (patch) | |
| tree | 76242ae2b19bad00796ed6d0104da8a0e4a99abe /cutTheSticks.cpp | |
| download | competitive-programming-a0d7b8320a8996eee0ed957b79c3a882f8b47146.tar.xz competitive-programming-a0d7b8320a8996eee0ed957b79c3a882f8b47146.zip | |
Added all current problems
Diffstat (limited to 'cutTheSticks.cpp')
| -rw-r--r-- | cutTheSticks.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/cutTheSticks.cpp b/cutTheSticks.cpp new file mode 100644 index 0000000..5c2c700 --- /dev/null +++ b/cutTheSticks.cpp @@ -0,0 +1,63 @@ +#include<bits/stdc++.h> + +using namespace std; + +bool vectorZero(vector<int>& v); +int secondSmallest(vector<int>& v); + +int main(){ + int vsize; + int count=0; + vector<int> vec; + cin >> vsize; + vector<int> result; + for(int i = 0; i < vsize; i++){ + int element; + cin >> element; + vec.push_back(element); + } + sort(vec.begin(), vec.end()); + int mn = *min_element(vec.begin(), vec.end()); + for(int i = 0; i < vsize; i++){ + if(vec[i] != 0){ + vec[i]-= mn; + } + } + cout << vsize; + while(!vectorZero(vec)){ + int ss = vec[secondSmallest(vec)]; + count = 0; + for(int x : vec){ + cout << x << " "; + } + cout << endl; + for(int i = 0; i < vsize; i++){ + if(vec[i] != 0){ + vec[i] -= ss; + count++; + } + } + cout << count << endl; + } + return 0; +} + + +bool vectorZero(vector<int>& v){ + int count = 0; + for(int i = 0; i < v.size(); i++){ + if(v[i] == 0){ + count++; + } + } + return count == v.size(); +} + +int secondSmallest(vector<int>& v){ + for(int i = 0; i < v.size(); i++){ + if(v[i] != *min_element(v.begin(), v.end())){ + return i; + } + } + return -1; +} |
