Submission showing run error for correct code

My submission is showing a run error although the code is correct. I have downloaded the test case giving error and tried it, the compile and test is giving corect result, but it’s not submitting… The code is:-

#include

using namespace std;

int main() {
long a[1000], n, key;
cin>>n;
for (int i=0; i<=n-1;i++) {
cin>>a[i];
}
cin>>key;
long s=0, e=n-1,mid;
while (s<=e) {
mid=(s+e)/2;
if (a[mid]==key) {
break;
}
if (a[s]<a[mid]) {
if (key<a[mid] and key>=a[s]) {
e=mid-1;
}
else {
s=mid+1;
}
}
else {
if (key<=a[e] and key>a[mid]) {
s=mid+1;
}
else {
e=mid-1;
}
}
}
if (a[mid]==key) {
cout<<mid;
}
else
cout<<-1;
return 0;
}

@Ayush280301 take larger array size of 10^5,


this is from your latest submission