- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCutTheSticks.java
More file actions
Latest commit
93 lines (69 loc) · 2.34 KB
/
Copy pathCutTheSticks.java
File metadata and controls
93 lines (69 loc) · 2.34 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
You are given N sticks, where the length of each stick is a positive integer. A cut operation is performed on the sticks such that all of them are reduced by the length of the smallest stick.
Suppose we have six sticks of the following lengths:
5 4 4 2 2 8
Then, in one cut operation we make a cut of length 2 from each of the six sticks. For the next cut operation four sticks are left (of non-zero length), whose lengths are the following:
3 2 2 6
The above step is repeated until no sticks are left.
Given the length of N sticks, print the number of sticks that are left before each subsequent cut operations.
Note: For each cut operation, you have to recalcuate the length of smallest sticks (excluding zero-length sticks).
Input Format
The first line contains a single integer N.
The next line contains N integers: a0, a1,...aN-1 separated by space, where ai represents the length of ith stick.
Output Format
For each operation, print the number of sticks that are cut, on separate lines.
Constraints
1 ≤ N ≤ 1000
1 ≤ ai ≤ 1000
*/
importjava.io.*;
importjava.util.*;
importjava.text.*;
importjava.math.*;
importjava.util.regex.*;
publicclassSolution {
publicstaticintmin(int [] arr)
{
intmini=arr[0];
for(inti=0;i<arr.length;i++)
{
if(arr[i]<mini&&arr[i]!=0)
{
mini=arr[i];
}
if(mini==0)
{
if(arr[i]>mini)
{
mini=arr[i];
}
}
}
returnmini;
}
publicstaticvoidmain(String[] args) {
Scannerin = newScanner(System.in);
intn = in.nextInt();
intarr[] = newint[n];
for(intarr_i=0; arr_i < n; arr_i++){
arr[arr_i] = in.nextInt();
}
intcount=0;
intminimum=min(arr);
while(minimum>0)
{
count=0;
for(inti=0;i<n;i++)
{
if(arr[i]>=1)
{
arr[i]=arr[i]-minimum;
count++;
}
}
System.out.println(count);
minimum=min(arr);
//System.out.println("min"+minimum);
}
}
}