fork download
  1. #include <algorithm>
  2. #include <iomanip>
  3. #include <iostream>
  4. #include <vector>
  5. #include <set>
  6. #include <numeric>
  7. #include <map>
  8. #include <unordered_map>
  9. using namespace std;
  10. #define all(a) a.begin(), a.end()
  11. #define ll long long
  12. #define fo(i,n) for (long long i = 0; i < n; i++)
  13. #define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  14. int main()
  15. {
  16. fastIO
  17. ll i,n,m,k,input;
  18. cin >> i;
  19. while (i--)
  20. {
  21. cin >> n >> m;
  22. vector<ll> a(n);
  23. bool cond = true;
  24. fo(j,n)
  25. {
  26. cin >> input;
  27. a[j] = input;
  28. }
  29. cin >> m;
  30. for (int j = 0; j < n; j++)
  31. {
  32. if (j == 0)
  33. {
  34. if (m-a[j] < a[j])
  35. {
  36. a[j] = m-a[j];
  37. }
  38. }
  39. else
  40. {
  41. if (m-a[j] <= a[j] && m-a[j] >= a[j-1])
  42. {
  43. a[j] = m-a[j];
  44. }
  45. else
  46. {
  47. if (a[j] < a[j-1])
  48. {
  49. a[j] = m-a[j];
  50. }
  51. }
  52. if (a[j] < a[j-1])
  53. {
  54. cond = false;
  55. break;
  56. }
  57. }
  58. }
  59. if (cond)
  60. {
  61. cout << "YES";
  62. }
  63. else
  64. {
  65. cout << "NO";
  66. }
  67. cout << '\n';
  68. }
  69. }
Success #stdin #stdout 0.01s 5280KB
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