Advertisement
Guest User

CodeForces 1293A

a guest
Feb 25th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. import java.util.*;
  2. public class sol{
  3.     static int n, s, k;
  4.     static int[] floors;
  5.     public static void main(String[] args){
  6.         Scanner console = new Scanner(System.in);
  7.         int t = console.nextInt();
  8.         for ( int i = 0; i < t; t++ )
  9.         {
  10.             n = console.nextInt();
  11.             s = console.nextInt();
  12.             k = console.nextInt();
  13.             floors = new int[n+1];
  14.             for ( int j = 0; j < k; j++ )
  15.             {
  16.                 floors[console.nextInt()] = -1;
  17.             }
  18.             System.out.println(function(0,n-1,floors,s)-s);
  19.         }
  20.     }
  21.     static int function ( int l , int r , int[] arr, int x )
  22.     {
  23.         int ans = -1;
  24.         while ( l <= r )
  25.         {
  26.             int mid = l + ( r - l ) / 2;
  27.             if ( mid >= x && arr[mid] != -1)
  28.             {
  29.                 ans = mid;
  30.             }
  31.             else
  32.             {
  33.                 l = mid + 1;
  34.             }
  35.         }
  36.         return ans;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement