fork download
  1. import math
  2. def f(m):
  3. tmp=lst[:]
  4. tmp[0]=m
  5. tmp.sort()
  6. # print()
  7. # print(m)
  8. idx=tmp.index(m)
  9. median=int(math.ceil(n/2))-1
  10. # print(idx,median)
  11. if idx==median:
  12. return True
  13. if idx>median:
  14. neg=False
  15. else:
  16. neg=True
  17. # print(neg)
  18. ct=0
  19. for i in range(n):
  20. if tmp[i]==m:
  21. continue
  22. if neg:
  23. if tmp[i]>m and -tmp[i]<m:
  24. ct+=1
  25. else:
  26. if tmp[i]<m and -tmp[i]>m:
  27. ct+=1
  28.  
  29. if ct>=abs(median-idx):
  30. return True
  31.  
  32. return False
  33.  
  34.  
  35.  
  36.  
  37. T=int(input())
  38. for __ in range(T):
  39. n=int(input())
  40. lst=list(map(int,input().split()))
  41.  
  42. if f(lst[0]) or f(-1*lst[0]):
  43. print("yes")
  44. continue
  45. print("no")
  46.  
Success #stdin #stdout 0.11s 14196KB
stdin
7
3
2 3 1
5
1 2 3 4 5
4
4 2 0 -5
4
-5 0 4 3
4
-10 8 3 2
1
1
10
9 1000 -999 -13 456 -223 23 24 10 0
stdout
yes
yes
yes
no
no
yes
yes