This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 3e5 + 25;
int n, a[MAXN], q;
int freq[MAXN];
int main () {
cin >> 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 < MAXN; i++) {
if (freq[i]) {
x.push_back(freq[i]);
}
}
sort(x.begin(), x.end());
ll mn = 1e18;
do {
ll r = 0, sum = 0;
for (auto i : x) {
sum += r * (r + 1) / 2 + (n - i - r) * (n - i - r + 1) / 2;
r += i;
}
sum = n * (n + 1) / 2 * ((int)x.size()) - sum;
if (sum < mn) {
// for (auto i : x) cout << i << " ";
// cout << '\n';
mn = sum;
}
} while (next_permutation(x.begin(), x.end()));
cout << mn << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |