fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #define ll long long
  5.  
  6. int cmp(const void *a, const void * b){
  7. int *p1 = (int*)a;
  8. int *p2 = (int*)b;
  9. return *p1 - *p2;
  10. }
  11.  
  12.  
  13.  
  14. void solve(){
  15. int n; scanf("%d", &n);
  16. int a[n+1];
  17. for(int i=1; i <=n; i++){
  18. scanf("%d", a + i);
  19. }
  20. int check[n+2] = {0};
  21. check[a[1]] = 1; //a[i] la vi tri ghe ma khach thu i ngoi;
  22. for(int i=2; i <=n; i++){
  23. if(!check[a[i] + 1] && !check[a[i] - 1]){
  24. printf("NO\n");
  25. return;
  26. }
  27. check[a[i]] = 1; //dat vi tri ghe a[i] = 1 (da co nguoi ngoi)
  28. }
  29. printf("YES\n");
  30. }
  31.  
  32. int main(){
  33. int typetest = 0;
  34. if(typetest){
  35. int t; scanf("%d", &t);
  36. while(t--){
  37. solve();
  38. }
  39. }else solve();
  40. }
Success #stdin #stdout 0s 5268KB
stdin
Standard input is empty
stdout
YES