-
Notifications
You must be signed in to change notification settings - Fork 0
/
cut_the_sticks.cpp
57 lines (40 loc) · 947 Bytes
/
cut_the_sticks.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
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#define MAXN 10001
using namespace std;
int n, cuts;
int A[MAXN];
int main( ) {
scanf( "%d", &n );
for ( int i = 1; i <= n; ++i ) {
scanf( "%d", &A[i] );
}
while ( true ) {
int Minim = -1;
for ( int j = 1; j <= n; ++j ) {
if ( A[j] == 0 ) {
continue;
}
if ( Minim == -1 ) {
Minim = A[j];
}else {
Minim = min( Minim, A[j] );
}
}
if ( Minim == -1 ) {
break;
}
cuts = 0;
for ( int i = 1; i <= n; ++i ) {
if ( A[i] >= Minim ) {
A[i] -= Minim;
++cuts;
}
}
printf( "%d\n", cuts );
}
return 0;
}