You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
554 B
27 lines
554 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
typedef long long LL;
|
|
const int N = 310;
|
|
int a[N];
|
|
int n;
|
|
LL res;
|
|
int h, t, cnt;
|
|
|
|
int main() {
|
|
cin >> n;
|
|
for (int i = 1; i <= n; i++) cin >> a[i];
|
|
sort(a + 1, a + n + 1);
|
|
//策略:从最低直接跳到最高,然后跳到次低,跳到次高...
|
|
t = n;
|
|
//双指针开始
|
|
while (h < t) {
|
|
cnt++;
|
|
res += pow(a[h] - a[t], 2);
|
|
if (cnt % 2 > 0)h++;
|
|
else t--;
|
|
}
|
|
//输出大吉
|
|
cout << res << endl;
|
|
return 0;
|
|
} |