Advertisement
Bassel_11

Untitled

Mar 25th, 2023
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.39 KB | None | 0 0
  1. /*
  2. ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠄⠒⠌⠔⣱⣒⣀⣄⡀⠀⠀⠒⠁⠛⠑⠆⠀⠊⠀⠠⠢⢰⠀⠀⠀⣀⡤⢖⣽⣾⣾⣿⣿⡿⣿⣿
  3. ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠂⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠨⠤⢴⣾⣴⣾⣿⣿⢿⣿⣿⣿⣿⡿⠟
  4. ⠀⠀⠀⠀⠀⠀⠀⠀⢀⠈⠄⠀⢀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠠⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠿⣿⣷⣿⣻⣿⣿⡿⠛⠁⡀⠄
  5. ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⡈⠁⣀⠡⠀⡁⠄⢤⡆⠀⡤⠀⡠⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠺⢿⣿⡿⠟⠋⠁⢀⠀⢂⠀⠄
  6. ⠀⠀⠀⠀⠀⠀⠀⠰⣒⠊⠁⠠⢀⠢⢁⠐⢆⡰⢯⡊⣆⠄⣀⣀⢀⡕⢀⠔⠀⢰⠂⠀⢀⠀⠀⠀⠀⠀⠀⢖⠋⠀⠠⠐⠈⡀⠐⡀⠄⠂
  7. ⠀⠀⠀⠀⠀⠀⠀⢀⣤⣛⠠⣑⡏⣰⡿⢺⢟⡭⠉⠙⡿⠐⢥⠀⠀⠀⠀⠀⠀⠈⢂⠐⠈⠀⠀⠀⠀⠀⠀⢢⡉⠠⠁⠐⠠⠐⠀⠄⠐⡀
  8. ⠀⠀⠀⠀⠀⠀⠀⣀⠔⠁⠠⢔⠣⢌⠢⡍⠈⠀⠀⠀⢠⠀⠀⠀⠀⠀⠄⠐⡄⠀⠀⠆⠀⠀⠀⠀⢀⢀⠠⡤⠽⠂⢀⠡⠐⠀⠡⠐⢀⠀
  9. ⠀⠀⠀⠀⠀⠀⠀⠉⠉⡹⠀⣤⠣⢌⢢⡁⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠆⠀⢲⡀⠀⢠⠀⠂⠀⢔⣥⡛⢤⣶⣤⣐⠀⡀⠂⢁⠐⠀⠂⡀
  10. ⠀⠀⠀⠀⠀⠀⠀⠀⠴⠕⡇⢎⡗⣈⡲⠁⠀⠀⢀⡇⢸⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⢼⠀⠀⢀⡞⣥⣸⣜⣿⣳⠿⣮⣥⣶⣤⣂⠁⠐⠀
  11. ⠀⠀⠀⠀⠀⠀⠀⠀⢠⢴⣃⢸⣏⢍⣛⢣⡀⠀⠈⠳⢈⠀⠀⠀⠀⣀⠼⡤⠄⠈⠀⠀⠀⣾⢫⣟⣖⢸⣿⣿⣿⣻⡵⢯⣿⣿⣆⠉⠳⣶
  12. ⠴⢻⡒⢦⣠⣀⠤⢔⠈⢀⡀⢿⠽⡜⠟⠻⠿⠓⢤⣄⠘⢱⣤⡶⣛⣁⣤⣇⣠⡤⠀⠀⠀⡧⣾⣟⡿⢸⢛⢿⣿⣷⣻⢻⡾⣍⢏⠳⣄⠈
  13. ⠀⠀⠙⠃⠢⢈⠧⡀⢳⡀⢱⡀⢶⢣⡣⢍⢩⡘⠯⢽⠀⠘⠁⠒⠈⠉⠉⢛⠉⠀⠀⠀⠀⣧⡞⣯⣼⡯⢌⠎⣿⣷⢯⣟⡽⣿⢘⣿⣿⣷
  14. ⠀⠀⠀⠀⠀⠉⠰⠌⡆⣷⠈⡆⠉⢰⣷⣊⠴⠡⠎⡽⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⢾⢻⣿⢹⠀⠈⢎⣿⣿⣻⢮⣟⣧⣿⣿⣿⢿
  15. ⡼⡳⡄⢀⡶⡀⠨⡁⠓⡄⡒⣏⣾⢻⣽⣷⡊⡕⢣⠹⢤⡤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⢟⣸⢿⢸⢀⠀⠘⣿⣿⣽⣻⢾⣽⡏⡕⣯⠞
  16. ⣙⠻⣧⢸⣗⣣⠀⢸⣴⣷⡟⣯⠷⠛⣼⡿⣿⡜⢤⠓⣼⠤⠄⠀⠠⠀⡀⠀⠀⠀⣠⠔⡱⣪⠞⠘⠈⠁⠀⠀⣿⣿⡷⣯⣟⣾⣗⢷⢸⡹
  17. ⠈⣽⡟⠈⠷⠏⢠⣟⣿⠗⠋⠁⠀⣼⡿⣽⣳⣿⣦⡙⣌⢒⠲⠲⠤⠀⠀⢀⡤⡚⡔⣊⡱⠋⡂⠀⠀⠀⠀⠀⣽⣿⣟⣷⣻⣞⣿⣸⠀⣹
  18. ⣴⡿⠗⣦⡀⠀⢠⡟⠁⠀⠀⠀⣼⡿⣽⣳⣿⣿⣿⣧⣜⢢⡆⣀⣀⡴⠞⣍⠲⡱⢘⡤⠁⡜⠀⠀⠀⡄⠀⠀⣾⣿⣿⣳⣟⣾⣻⣏⠀⢰
  19. ⡟⡴⢂⠈⢧⠜⣫⣾⣶⣄⠀⣸⣿⣽⣳⣯⣿⣿⣿⣿⣿⣏⠹⣹⣶⣉⠞⣠⢣⡕⠉⢀⣼⠃⠀⠀⠀⣻⡄⠀⣻⣿⣿⣿⣞⣷⣻⢿⣿⣦
  20. ⣇⠐⠠⡱⢢⣾⣿⣽⣟⣾⣷⣿⣳⢯⣷⡿⢸⣿⣿⣿⣿⣇⢣⠧⡈⠅⠉⠉⠁⠀⢀⣜⠆⠀⠀⠀⠀⢹⡜⣄⣻⣿⣿⣿⣞⡷⣯⣿⣿⣻
  21. ⢳⣭⠟⡠⣹⣿⣿⣟⣾⣿⣟⣷⣻⣯⣿⠋⢸⣿⣿⣿⣿⡷⢮⠥⢹⣆⠀⠀⠀⣔⣣⠾⠔⠒⠒⠚⠉⠉⠁⢀⣿⣿⣿⣿⣿⡽⣷⢯⣿⣿
  22. ⠀⣿⣸⣴⣿⣿⣳⣿⣿⣳⡿⣾⣽⣯⢻⠀⢸⣿⣿⣿⣿⣇⠻⠀⠀⠈⠁⠀⠈⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣻⣟⣷⣿
  23. ⣾⣿⣿⣿⣿⣽⣿⣟⣾⢿⣽⠟⣹⠁⢸⠀⢸⣿⣿⣿⣿⡇⣏⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣄⡄⣿⣿⣿⣿⣿⣿⣿⣷⢿⣻⣾
  24. ⣿⣿⣿⣿⡿⣯⣷⡿⣯⡿⠋⠀⠀⠀⣸⠀⠰⣿⣿⣿⣿⣏⠼⠀⠀⠀⢰⠀⠀⠀⠀⠀⠀⠀⠀⢀⡄⠀⢠⣿⣿⣿⣿⣿⣿⠇⠻⣟⣯⣿
  25. ⣿⣿⣿⢯⣿⡿⣽⡿⠟⡃⠀⡀⠀⠀⡆⠀⠀⣿⣿⣿⣿⡧⢫⡅⠀⠀⠈⡄⠀⠀⠀⠀⠀⠀⠸⠃⠂⠀⣾⣿⣿⣿⣿⣿⡟⠀⡠⢹⢻⣿
  26. ⣿⣿⣽⣿⣿⠝⠁⠀⠀⢧⠀⡆⠀⠀⠀⠀⠀⣿⣿⣿⣿⣗⢣⢞⣄⠀⠀⢟⣆⠀⠀⠀⢠⠜⠁⠀⠀⣸⣿⣿⣿⣿⣿⡿⠁⠀⢇⢸⠀⠙
  27. */
  28. // IAM Batman
  29. //           Vengeance
  30. //                    Maybe im the problem
  31. #include <bits/stdc++.h>
  32. #define ll long long
  33. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" \<< "\n";
  34. #define ln cout << endl;
  35. #define c(n) cout << n;
  36. #define fix cout << fixed << setprecision(6);
  37. #define sz(x) int(x.size())
  38. #define loop(n) for (int i = 0; i < n; i++)
  39. #define loop1(n) for (int i = 1; i < n; i++)
  40. #define vi vector<int>
  41. #define vll vector<long long>
  42. #define all(s) s.begin(), s.end()
  43. #define srt(arr, n) sort(arr, arr + n);
  44. #define prefixsum(arr, n)        \
  45.     for (int i = 1; i <= n; i++) \
  46.     {                            \
  47.         arr[i] += arr[i - 1];    \
  48.     }
  49. #define upper(s) transform(all(s), s.begin(), ::toupper);
  50. #define lower(s) transform(all(s), s.begin(), ::tolower);
  51. #define pi 3.141592653
  52. #define pb push_back
  53. #define vc vector<char>
  54. #define sz(s) s.size()
  55. #define supra_mk4 ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  56. #define ulli unsigned ll int
  57.  
  58. using namespace std;
  59.  
  60. void Bassel()
  61. {
  62.     // supra_mk4
  63. #ifndef ONLINE_JUDGE
  64.     freopen("input.txt", "r", stdin),
  65.         freopen("output.txt", "w", stdout);
  66. #endif
  67. }
  68.  
  69. void solve1()
  70. {
  71.     int n;
  72.     cin >> n;
  73.     int a[n];
  74.     int sum = 0;
  75.     loop(n)
  76.     {
  77.         cin >> a[i];
  78.         sum += a[i];
  79.     }
  80.     int avg = sum / n;
  81.     // cout<<"avg:"<<avg<<" ";
  82.     int cost = 0;
  83.     for (int i = 0; i < n; i++)
  84.     {
  85.         cost += pow((a[i] - avg), 2);
  86.     }
  87.     cout << cost << "\n";
  88. }
  89.  
  90. int main()
  91. {
  92.     Bassel();
  93.     supra_mk4 int t = 1;
  94.     cin >> t;
  95.     while (t--)
  96.     {
  97.         solve1();
  98.     }
  99.  
  100.     return 0;
  101. }
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement