File tree Expand file tree Collapse file tree 1 file changed +71
-0
lines changed
Expand file tree Collapse file tree 1 file changed +71
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.BufferedReader ;
3+ import java.io.IOException ;
4+ import java.io.InputStreamReader ;
5+ import java.util.* ;
6+
7+ public class Main {
8+
9+ static int problemCnt;
10+ static Long ans;
11+ static long [] arr;
12+
13+ public static void main (String [] args ) throws NumberFormatException , IOException {
14+ init();
15+ process();
16+ print();
17+ }
18+
19+ public static void init () throws NumberFormatException , IOException {
20+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
21+ problemCnt = Integer . parseInt(br. readLine());
22+ StringTokenizer st = new StringTokenizer (br. readLine());
23+ ans = 1000_000_0000L ;
24+ arr = new long [problemCnt];
25+ for (int i = 0 ; i < problemCnt; i++ ) {
26+ arr[i] = Long . parseLong(st. nextToken());
27+ }
28+
29+
30+
31+ }
32+
33+ public static void process () {
34+ Long st = 1L ;
35+ Long end = 1000_000_001L ;
36+ Long mid = (st+ end)/ 2 ;
37+
38+ while (st < end) {
39+ boolean result = test(mid);
40+
41+ if (result) {
42+ ans = Math . min(ans, mid);
43+ end = mid;
44+ } else st = mid+ 1 ;
45+
46+ mid = (st+ end)/ 2 ;
47+
48+ }
49+ }
50+
51+
52+ private static boolean test (Long diff ) {
53+ long cnt = 0 ;
54+
55+ for (int i = 0 ; i < problemCnt; i++ ) {
56+ long result = arr[i]/ diff;
57+ if (arr[i]% diff == 0 ) result-- ;
58+ cnt += result;
59+ }
60+
61+ if (cnt >= problemCnt) return false ;
62+
63+
64+ return true ;
65+ }
66+
67+ public static void print () {
68+ System . out. println(ans);
69+ }
70+ }
71+ ```
You can’t perform that action at this time.
0 commit comments