AnupamRoy's blog

By AnupamRoy, history, 3 days ago, In English

include<bits/stdc++.h>

using namespace std; int main() { int i,n,t,j,p,k; cin>>n; for(i=0;i<n;i++) { cin>>p>>k>>t; int a[t],r,s; int b[p+1]={0}; for(j=0;j<t;j++) { cin>>a[j]; b[a[j]]++; } for(j=k;j>=1;j--) { if(b[j]==0) { break; } } if(j==0) { r=2000000000; } else{ r=abs(j-k); } for(j=k;j<=p;j++) { if(b[j]==0) { break; } } if(j==(p+1)) { s=2000000000; } else{ s=abs(j-k); } if(r==s) {cout<<r<<endl; } else{ cout<<min(r,s)<<endl; }

}

}

 
 
 
 
  • Vote: I like it
  • -17
  • Vote: I do not like it

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

With line int b[p+1]={0};, you are creating a really big array, since p can be as large as $$$10^9$$$.