fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n, k;
  7. cin >> n >> k;
  8. vector<int> a(n);
  9. for (auto &i : a)
  10. cin >> i;
  11. vector<int> b = a;
  12. sort(b.begin(), b.end());
  13. for (int i = 0; i < n; i++)
  14. {
  15. if ((a[i] % k) != (b[i] % k))
  16. {
  17. cout << "NO\n";
  18. return 0;
  19. }
  20. }
  21. cout << "YES\n";
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5316KB
stdin
5 7
14 19 13 7 12
stdout
YES