40 lines
893 B
C++
40 lines
893 B
C++
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
const int N = 110;
|
|
typedef long long LL;
|
|
int a[N] = {1, 2, 3, 6, 3};
|
|
int b[N] = {3, 4, 1, 6, 5};
|
|
int n = 5;
|
|
|
|
int k1 = 2, k2 = 3, k = k1 + k2;
|
|
LL res;
|
|
|
|
int main() {
|
|
priority_queue<int> pq; // 默认创建最大堆
|
|
|
|
// 将两个数组的差值绝对值放到最大堆中
|
|
for (int i = 0; i < n; i++) pq.push(abs(a[i] - b[i]));
|
|
|
|
for (int i = 1; i <= k; i++) {
|
|
int mx = pq.top();
|
|
pq.pop();
|
|
if (mx == 0) {
|
|
if ((k - i) % 2 == 0)
|
|
cout << 0 << endl;
|
|
else
|
|
cout << 1 << endl;
|
|
exit(0);
|
|
}
|
|
pq.push(mx - 1);
|
|
}
|
|
// 计算值
|
|
while (pq.size()) {
|
|
int mx = pq.top();
|
|
if (mx == 0) break;
|
|
pq.pop();
|
|
res += mx * mx;
|
|
}
|
|
cout << res << endl;
|
|
return 0;
|
|
} |