Advertisement
LEGEND2004

Permutation Check

Aug 8th, 2023
977
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. signed main()
  7. {
  8.     int n;
  9.     cin >> n;
  10.     vector<int> a(n);
  11.     for(int i = 0; i < n; i++){
  12.         cin >> a[i];
  13.     }
  14.     sort(a.begin(), a.end());
  15.     bool ok = true;
  16.     for(int i = 0; i < n; i++){
  17.         if(a[i] != (i + 1)){
  18.             ok = false;
  19.             break;
  20.         }
  21.     }
  22.     cout << (ok ? "Yes" : "No") << endl;
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement