C++求助!样例没问题,但是零分。
查看原帖
C++求助!样例没问题,但是零分。
878171
SproutingRRR楼主2024/5/4 20:49
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e2 + 2;
int n; //石头个数
int a[MAXN];
long long ans;
bool cmp(int x, int y) {
	return x > y;
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	ans += a[0] * a[0];
	sort(a, a + n, cmp);
	int left_, right_;
	n -= 1;
	left_ = 0;
	right_ = n;

	while (n > 0) {
		int temp = a[left_] - a[right_];
		ans += temp * temp;
		left_++;
		n--;
	}

	cout << ans;
	return 0;
}
2024/5/4 20:49
加载中...