Saleh127

codeforces 1154Bcpp

Jun 5th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define Faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. #define pi acos(-1)
  7. #define yes printf("YES\n");
  8. #define no printf("NO\n");
  9. int main()
  10. {
  11. Faster
  12.  
  13. ll c,d,e,f,i,j,k,l;
  14. cin>>c;
  15. vector<ll>a(c) ;
  16. for(i=0;i<c;i++)
  17. {
  18. cin>>a[i];
  19. }
  20. sort(a.begin(),a.end());
  21. a.resize(unique(a.begin(), a.end()) - a.begin());
  22. d=a.size();
  23. if(d>3) cout<<-1<<endl;
  24. else if(d==1) cout<<0<<endl;
  25. else if(d==2)
  26. {
  27. e=a[1]-a[0];
  28. if(e%2==0)
  29. {
  30. cout<<e/2<<endl;
  31. }
  32. else
  33. {
  34. cout<<e<<endl;
  35. }
  36. }
  37. else if(d==3)
  38. {
  39. e=a[1]-a[0];
  40. f=a[2]-a[1];
  41. if(e==f)
  42. {
  43. cout<<e<<endl;
  44. }
  45. else
  46. {
  47. cout<<-1<<endl;
  48. }
  49. }
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment