Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID: mickyta1
- TASK: skidesign
- LANG: C++
- */
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 1000 + 5;
- int arr[N];
- int main(){
- freopen("skidesign.in", "r", stdin);
- freopen("skidesign.out", "w", stdout);
- int n;
- scanf("%d", &n);
- int lwb = 100;
- int upb = 0;
- for(int i = 1; i <= n; ++i){
- scanf("%d", &arr[i]);
- lwb = min(lwb, arr[i]);
- upb = max(upb, arr[i]);
- }
- if(upb - lwb <= 17){
- cout << "0\n";
- fclose(stdin);
- fclose(stdout);
- return 0;
- }
- int mn = 1e9;
- for(int l = lwb; l < upb - 17; ++l){
- int r = l + 17;
- int sum = 0;
- for(int j = 1; j <= n; ++j){
- if(arr[j] < l){
- int dif = l - arr[j];
- sum += dif * dif;
- } else if(arr[j] > r){
- int dif = arr[j] - r;
- sum += dif * dif;
- }
- }
- mn = min(mn, sum);
- }
- cout << mn << '\n';
- fclose(stdin);
- fclose(stdout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement