Guest User

10

a guest
Aug 25th, 2019
71
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int n;
  5. scanf("%d",&n);
  6. int arr[n];
  7. for(int i=0;i<n;i++)
  8. scanf("%d",&arr[i]);
  9. int flag;
  10. do
  11. {
  12. flag=0;
  13. for(int i=0;i<n-1;i++)
  14. {
  15. if(arr[i]>arr[i+1])
  16. {
  17. arr[i] = arr[i]+arr[i+1];
  18. arr[i+1]= arr[i]-arr[i+1];
  19. arr[i] = arr[i]-arr[i+1];
  20. flag = 1;
  21. }
  22. }
  23. }while(flag!=0);
  24. flag = arr[0];
  25. for(int i=0;i<n;i++)
  26. {
  27. if(arr[i]==flag)
  28. flag++;
  29. }
  30. if(flag==(arr[n-1]+1))
  31. printf("YES");
  32. else
  33. printf("NO");
  34. }
RAW Paste Data