fork download
  1. # your code goes here
  2. t=int(input())
  3. for _ in range(t):
  4. n,m=map(int,input().split())
  5. a=list(map(int,input().split()))
  6. b=int(input())
  7. if(n==1):
  8. print("YES")
  9. continue
  10. pr = -10**18
  11. c = True
  12. for x in a:
  13. #op1 = x
  14. #op2 = b - x
  15. if(x<b-x):
  16. mini=x
  17. maxi=b-x
  18. else:
  19. mini=b-x
  20. maxi=x
  21. #mini = min(op1, op2)
  22. #maxi = max(op1, op2)
  23. if mini>=pr:
  24. pr=mini
  25. elif maxi>=pr:
  26. pr=maxi
  27. else:
  28. c = False
  29. break
  30. if(c):
  31. print("YES")
  32. else:
  33. print("NO")
  34.  
  35.  
  36.  
  37.  
Success #stdin #stdout 0.11s 14136KB
stdin
5
1 1
5
9
3 1
1 4 3
3
4 1
1 4 2 5
6
4 1
5 4 10 5
4
3 1
9 8 7
8
stdout
YES
NO
YES
NO
YES