12562 | 2024-12-23 12:25:09 | 4rt3xp0 | 2016. február | cpp17 | Accepted | 1ms | 508 KiB |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
vector<int> h(n);
for(int &i: h) cin >> i;
int mn=INT_MAX;
for(int x=0;x<=83;x++){
int s=0;
for(int i: h){
int tmp=0;
if(i<x) tmp=x-i;
else if(i>x+17) tmp=i-x-17;
s+=tmp*tmp;
}
mn=min(mn,s);
}
cout << mn;
}
18
Expected output:18
Checker output:ok 1 number(s): "18"
298455
Expected output:298455
Checker output:ok 1 number(s): "298455"
208584
Expected output:208584
Checker output:ok 1 number(s): "208584"
107040
Expected output:107040
Checker output:ok 1 number(s): "107040"
210876
Expected output:210876
Checker output:ok 1 number(s): "210876"
280598
Expected output:280598
Checker output:ok 1 number(s): "280598"
206286
Expected output:206286
Checker output:ok 1 number(s): "206286"
54651
Expected output:54651
Checker output:ok 1 number(s): "54651"
88767
Expected output:88767
Checker output:ok 1 number(s): "88767"
9518
Expected output:9518
Checker output:ok 1 number(s): "9518"
427475
Expected output:427475
Checker output:ok 1 number(s): "427475"
419533
Expected output:419533
Checker output:ok 1 number(s): "419533"
250041
Expected output:250041
Checker output:ok 1 number(s): "250041"
478932
Expected output:478932
Checker output:ok 1 number(s): "478932"
291469
Expected output:291469
Checker output:ok 1 number(s): "291469"
204043
Expected output:204043
Checker output:ok 1 number(s): "204043"
53653
Expected output:53653
Checker output:ok 1 number(s): "53653"
333176
Expected output:333176
Checker output:ok 1 number(s): "333176"
47796
Expected output:47796
Checker output:ok 1 number(s): "47796"
154982
Expected output:154982
Checker output:ok 1 number(s): "154982"
134811
Expected output:134811
Checker output:ok 1 number(s): "134811"
323963
Expected output:323963
Checker output:ok 1 number(s): "323963"