-
Notifications
You must be signed in to change notification settings - Fork 0
/
CutSticks.cpp
52 lines (47 loc) · 1.03 KB
/
CutSticks.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int getmin(vector<int> v) {
if(!v.empty()) {
int temp = v[0];
for(int i = 1; i < v.size(); i++)
if(temp > v[i])
temp = v[i];
return temp;
}
else
return 0;
}
void removezeros(vector<int> &v) {
for(int i = 0; i < v.size();)
if(v[i] <= 0)
v.erase(v.begin()+i);
else
i++;
}
int main() {
int n;
cin >> n;
vector<int> sticks;
for(int i = 0; i < n; i++) {
int elem;
cin >> elem;
sticks.push_back(elem);
}
while(!sticks.empty()) {
int count = sticks.size();
int min = getmin(sticks);
for(int i = 0; i < sticks.size(); i++) {
if(sticks[i] >= min)
sticks[i] -= min;
else
count--;
}
removezeros(sticks);
cout << count << endl;
}
return 0;
}