Recieving runtime error during submission in c++?

Revision en1, by AnupamRoy, 2021-02-23 10:40:37

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; }

}

}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English AnupamRoy 2021-02-23 10:40:37 964 Initial revision (published)