-
Notifications
You must be signed in to change notification settings - Fork 1
/
CutTheSticks.cpp
65 lines (49 loc) · 957 Bytes
/
CutTheSticks.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
53
54
55
56
57
58
59
60
61
62
63
64
65
// problem: "https://www.hackerrank.com/challenges/cut-the-sticks/problem"
#include<iostream>
using namespace std;
int main()
{
int A[1000],n,min,t,count,i,s;
cin>>n;
for(i=0;i<n;i++)
cin>>A[i];
min=A[0];
for(i=0;i<n;i++)
if(min>A[i])
min=A[i];
i=0;
t=min;
count=0;
s=0;
cout<<n<<endl;
while(1)
{
A[i]=A[i]-t;
if(s==0)
{
if(A[i]>0)
{
min=A[i];
s=-1;
}
}
if(A[i]>0)
{
count++;
if(min>A[i])
min=A[i];
}
i++;
if(i==n)
{
if(count==0)
break;
cout<<count<<endl;
t=min;
count=0;
i=0;
s=0;
}
}
return 0;
}