---
# System prepended metadata

title: f679. 公會成員

---

# f679. 公會成員
## 題目連結: [f679](https://zerojudge.tw/ShowProblem?problemid=f679)

## 解題想法
* 用遞迴做二分搜尋

## 程式碼
```python=
import sys

def search(arr):
    global want    
    mid = int(1/2*len(arr))
    
    if want == arr[mid]:
        return "Yes"
    elif len(arr) == 1:
        return "No"
    elif want < arr[mid]:
        return search(arr[:mid])
    else:
        return search(arr[mid:])

#start
ppl, que = map(int,input().split())
data = [int(i) for i in input().split()]

for i in range(que):
    want = int(sys.stdin.readline())
    print(search(data)
```
### 但是遇到TLE，所以改成用迴圈做

```python=
import sys

ppl, que = map(int,input().split())
data = [int(i) for i in input().split()]

for i in range(que):
    want = int(input())
    s = 0
    end = ppl-1
    while True:
        mid = int((s+end)/2)
         
        if want == data[mid]:
            print("Yes")
            break
        elif s+1 == end:
            print("No")
            break
        elif want < data[mid]:
            end = mid
        else:
            s = mid
```
### 但還是TLE😥