File tree 1 file changed +39
-0
lines changed
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+ import java .util .*;
3
+
4
+ public class Main {
5
+
6
+ public static void main (String [] args ) throws IOException {
7
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
8
+ StringTokenizer st = new StringTokenizer (br .readLine ());
9
+ int N = Integer .parseInt (st .nextToken ());
10
+ int M = Integer .parseInt (st .nextToken ());
11
+ int [] jewel = new int [M ];
12
+ int max = Integer .MIN_VALUE ;
13
+ for (int i = 0 ; i < M ; i ++) {
14
+ jewel [i ] = Integer .parseInt (br .readLine ());
15
+ max = Math .max (max , jewel [i ]);
16
+ }
17
+ Arrays .sort (jewel );
18
+ int answer = max ;
19
+ int low = 1 ;
20
+ int high = max ;
21
+ while (low <= high ) {
22
+ int mid = (low + high ) / 2 ;
23
+ int count = 0 ;
24
+ for (int j = 0 ; j < M ; j ++) {
25
+ count += jewel [j ] / mid ;
26
+ if (jewel [j ] % mid != 0 ) {
27
+ count ++;
28
+ }
29
+ }
30
+ if (count > N ) {
31
+ low = mid + 1 ;
32
+ } else {
33
+ answer = Math .min (answer , mid );
34
+ high = mid - 1 ;
35
+ }
36
+ }
37
+ System .out .println (answer );
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments