Advertisement
Guest User

Untitled

a guest
Sep 14th, 2016
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. long long a[100005],n,i,res,x,y,f=0;
  6. cin>>n;
  7. for(i=0; i<n; i++)
  8. cin>>a[i];
  9. sort(a,a+n);
  10. x=a[0];
  11.  
  12. for(i=1; i<n; i++)
  13. {
  14. if(x!=a[i])
  15. {
  16. y=a[i];
  17. f=1;
  18. break;
  19. }
  20.  
  21. }
  22. if(f==1)
  23. {
  24. f=0;
  25. res=y-x;
  26. x=x+res;
  27. for(i=0; i<n; i++)
  28. {
  29.  
  30. if(res>=a[i])
  31. a[i]=res+a[i];
  32. else if(a[i]>res&&x!=a[i])
  33. a[i]=a[i]-res;
  34.  
  35. }
  36.  
  37. for(i=0; i<n-1; i++)
  38. {
  39.  
  40. if(a[i]!=a[i+1])
  41. f=1;
  42. }
  43.  
  44. if(f==0&&a[0]==a[n-1])
  45. cout<<"YES"<<endl;
  46. else
  47. cout<<"NO"<<endl;
  48. }
  49. else
  50. cout<<"YES"<<endl;
  51.  
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement