Advertisement
Saleh127

atc 043C

Sep 3rd, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; while(t--)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. ll a[1000],c,d,i,j,k,l=1e13;
  11. cin>>c;
  12. for(i=0;i<c;i++)
  13. {
  14. cin>>a[i];
  15. }
  16. sort(a,a+c);
  17. for(i=a[0];i<=a[c-1];i++)
  18. {
  19. d=0;
  20. for(j=0;j<c;j++)
  21. {
  22. d+=(a[j]-i)*(a[j]-i);
  23. }
  24. if(d<l)
  25. {
  26. l=d;
  27. }
  28. }
  29. cout<<l<<endl;
  30. return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement