AcWing 1353. 滑雪场设计
原题链接
简单
作者:
acw_weian
,
2021-01-27 21:52:20
,
所有人可见
,
阅读 469
/**
* 要证明区间一定落在[0,100]之间, 反证法
* 枚举所有区间,计算代价
*/
import java.util.*;
class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
for(int i = 0; i < n; i++) a[i] = sc.nextInt();
int res = (int)1e9;
for(int l = 0; l + 17 <= 100; l++){
int r = l + 17, cost = 0;
for(int j = 0; j < n; j++){
if(a[j] < l) cost += (a[j] - l) * (a[j] - l);
else if(a[j] > r) cost += (r - a[j]) * (r - a[j]);
}
res = Math.min(res, cost);
}
System.out.println(res);
}
}