为什么这样写不对呀
luogu:
#include <stdio.h>
#define N 100010
int n,m,x;
int arr[N];
int binary(int n,int x)
{
int left,middle,right;
left=0;
right=n+1;
while(left+1<right)
{
middle=(left+right)/2;
if(arr[middle]<x)
left=middle;
else
right=middle;
}
if(arr[right]==x)
return right;
else
return -1;
}
int main(void)
{
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&arr[i]);
for(int i=1;i<=m;i++)
{
scanf("%d",&x);
int res=binary(n,x);
printf("%d ",res);
}
return 0;
}
请问错误在哪?