#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 3e5 + 25;
int n, a[MAXN], q, n1;
int freq[MAXN];
int main () {
cin >> n1;// >> n >> q;
//for (int i = 1; i <= n; i++) cin >> a[i];
//sort(a + 1, a + n + 1);
//for (auto i : a) freq[i]++;
vector <int> x;
for (int i = 1; i <= n1; i++) {
int y;
cin >> y; n += y;
x.push_back(y);
}
//for (int i = 1; i < MAXN; i++) {
// if (freq[i]) {
// x.push_back(freq[i]);
// }
//}
sort(x.begin(), x.end());
deque <int> y;
for (int i = n1 - 1; i >= 0; i -= 2) y.push_front(x[i]);
for (int i = n1 - 2; i >= 0; i -= 2) y.push_back(x[i]);
ll mn = 1e18;
ll r = 0, sum = 0;
for (auto i : y) {
sum += r * (r + 1) / 2 + (n - i - r) * (n - i - r + 1) / 2;
r += i;
}
sum = ll(n) * ll((n + 1)) / 2 * ((ll)y.size()) - sum;
mn = sum;
cout << mn << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |