Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class sol{
- static int n, s, k;
- static int[] floors;
- public static void main(String[] args){
- Scanner console = new Scanner(System.in);
- int t = console.nextInt();
- for ( int i = 0; i < t; t++ )
- {
- n = console.nextInt();
- s = console.nextInt();
- k = console.nextInt();
- floors = new int[n+1];
- for ( int j = 0; j < k; j++ )
- {
- floors[console.nextInt()] = -1;
- }
- System.out.println(function(0,n-1,floors,s)-s);
- }
- }
- static int function ( int l , int r , int[] arr, int x )
- {
- int ans = -1;
- while ( l <= r )
- {
- int mid = l + ( r - l ) / 2;
- if ( mid >= x && arr[mid] != -1)
- {
- ans = mid;
- }
- else
- {
- l = mid + 1;
- }
- }
- return ans;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement