File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed
Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.util.* ;
3+ import java.io.* ;
4+
5+ public class boj1561 {
6+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
7+ static StringTokenizer st;
8+ static void nextLine () throws Exception {st = new StringTokenizer (br .readLine ());}
9+ static int nextInt() {return Integer . parseInt(st. nextToken());}
10+
11+ static long N ;
12+ static int M , max = 0 ;
13+ static int [] time;
14+ public static void main(String [] args) throws Exception {
15+ nextLine();
16+ N = nextInt();
17+ M = nextInt();
18+ time = new int [M + 1 ];
19+ nextLine();
20+ for (int i = 1 ; i <= M ; i++ ) {
21+ time[i] = nextInt();
22+ max = Math . max(max, time[i]);
23+ }
24+ if (N <= M ) {
25+ System . out. println(N );
26+ return ;
27+ } else {
28+ long t = search();
29+
30+ long cnt = M ;
31+ for (int i = 1 ; i <= M ; i++ )
32+ cnt += (t - 1 ) / time[i];
33+
34+ for (int i = 1 ; i <= M ; i++ ) {
35+
36+ if (t % time[i] == 0 )
37+ cnt++ ;
38+
39+ if (cnt == N ) {
40+ System . out. println(i);
41+ return ;
42+ }
43+ }
44+ }
45+ }
46+ static long search() {
47+ long start = 0 ;
48+ long end = N / M * max;
49+ while (start <= end) {
50+ long mid = (start + end) / 2 ;
51+ long sum = M ;
52+ for (int i = 1 ; i <= M ; i++ ) sum += mid / time[i];
53+ if (sum < N ) start = mid + 1 ;
54+ else end = mid - 1 ;
55+ }
56+ return start;
57+ }
58+ }
59+ ```
You can’t perform that action at this time.
0 commit comments