fork download
  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4. int main()
  5. {
  6. int count,flag,m;
  7. long long int n,temp,t;
  8. cin>>t;
  9. while(t--)
  10. {
  11. flag=1;
  12. count=1;
  13. cin>>n>>m;
  14. long long int unluck[m];
  15. for(int i=0;i<m;i++)
  16. cin>>unluck[i];
  17. sort(unluck,unluck+m);
  18. if(unluck[0]==1||unluck[m-1]==n) //unlucky tiles at beginning or end
  19. flag=0;
  20. int z=0;
  21. while(z<m-1&&flag==1)
  22. {
  23. if(unluck[z+1]==unluck[z]+1)
  24. count++;
  25. else
  26. count=1;
  27. if(count>=3)//number of unlucky tiles
  28. flag=0;
  29. z++;
  30. }
  31. if(flag==0)
  32. cout<<"NO"<<endl;
  33. else
  34. cout<<"YES"<<endl;
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0s 2736KB
stdin
2
10 6
2 4 8 3 6 7
10 5
2 4 5 7 9
stdout
NO
YES