import java.util.*; public class Main { static int N; static int M; static int K; public static void main(String args[] ){ Scanner sc =new Scanner(System.in); //2分探索 N = sc.nextInt(); M = sc.nextInt(); K = sc.nextInt(); String op = sc.next(); int B[] = new int[M]; int A[] =new int[N]; int ans = 0; for(int i = 0 ;i=K) { return 0; }else { return -1; } } int min_diff=Integer.MAX_VALUE; int left = 0; int right =B.length-1; int min_diff_right=0; int min_diff_left=0; int closest_num=-1; while(left <= right) { int mid = left +(right-left)/2; //中心の左右の値と目標との差を計算する。 if (mid + 1 < B.length) { min_diff_right = B[mid+1]+A - K; } if (mid > 0) { min_diff_left = B[mid-1]+A - K; } if (min_diff_left < min_diff && min_diff_left > 0) { min_diff = min_diff_left; closest_num = mid - 1; } if (min_diff_right < min_diff && min_diff_right > 0) { min_diff = min_diff_right; closest_num = mid + 1; } if (B[mid]+A < K) { left = mid + 1; }else if (B[mid]+A> K) { right = mid - 1 ; }else { return mid; } } System.out.println(closest_num); return closest_num; } public static int Pbinary_search_find_closet(int A,int B[]){ //2分探索 int min_diff=Integer.MAX_VALUE; int left = 0; int right =B.length-1; int min_diff_right=0; int min_diff_left=0; int closest_num=-1; if(B.length == 1) { if(A*B[0]>=K) { return 0; }else { return -1; } } while(left <= right) { int mid = left +(right-left)/2; //中心の左右の値と目標との差を計算する。 if (mid + 1 < B.length) { min_diff_right = B[mid+1]*A - K; } if (mid > 0) { min_diff_left = B[mid-1]*A - K; } // 最初の差と最も最小に近い値を更新する。 if (min_diff_left < min_diff && min_diff_left > 0) { min_diff = min_diff_left; closest_num = mid - 1; } if (min_diff_right < min_diff && min_diff_right > 0) { min_diff = min_diff_right; closest_num = mid + 1; } if (B[mid]*A < K) { left = mid + 1; }else if (B[mid]*A> K) { right = mid - 1 ; }else { return mid; } } return closest_num; } }