Advertisement
jakaria_hossain

codechef - chef and linear chess

Aug 10th, 2020
1,077
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define fast() (ios_base::sync_with_stdio(0),cin.tie(NULL));
  5. int main()
  6. {
  7.     fast();
  8.     int t;
  9.     cin>>t;
  10.     while(t--)
  11.     {
  12.         int n,k;
  13.         cin>>n>>k;
  14.         int ara[n+1],sum=1e9,ans=-1;
  15.         for(int i=0; i<n; i++)
  16.         {
  17.             cin>>ara[i];
  18.             if(k%ara[i]==0)
  19.             {
  20.                 int x=k/ara[i]-1;
  21.                 if(x<sum)
  22.                 {
  23.                     sum=x;
  24.                     ans=ara[i];
  25.                 }
  26.  
  27.             }
  28.         }
  29.         cout<<ans<<endl;
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement