#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 = ll(n) * ll((n + 1)) / 2 * ((ll)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 |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2492 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2488 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
3 ms |
2392 KB |
Output is correct |
4 |
Correct |
20 ms |
2496 KB |
Output is correct |
5 |
Correct |
114 ms |
2888 KB |
Output is correct |
6 |
Correct |
970 ms |
3256 KB |
Output is correct |
7 |
Correct |
961 ms |
3192 KB |
Output is correct |
8 |
Correct |
964 ms |
3208 KB |
Output is correct |
9 |
Correct |
965 ms |
3216 KB |
Output is correct |
10 |
Correct |
964 ms |
3244 KB |
Output is correct |
11 |
Correct |
963 ms |
3236 KB |
Output is correct |
12 |
Correct |
986 ms |
3252 KB |
Output is correct |
13 |
Correct |
952 ms |
3236 KB |
Output is correct |
14 |
Correct |
970 ms |
3224 KB |
Output is correct |
15 |
Correct |
957 ms |
3408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
3 ms |
2392 KB |
Output is correct |
4 |
Correct |
20 ms |
2496 KB |
Output is correct |
5 |
Correct |
114 ms |
2888 KB |
Output is correct |
6 |
Correct |
970 ms |
3256 KB |
Output is correct |
7 |
Correct |
961 ms |
3192 KB |
Output is correct |
8 |
Correct |
964 ms |
3208 KB |
Output is correct |
9 |
Correct |
965 ms |
3216 KB |
Output is correct |
10 |
Correct |
964 ms |
3244 KB |
Output is correct |
11 |
Correct |
963 ms |
3236 KB |
Output is correct |
12 |
Correct |
986 ms |
3252 KB |
Output is correct |
13 |
Correct |
952 ms |
3236 KB |
Output is correct |
14 |
Correct |
970 ms |
3224 KB |
Output is correct |
15 |
Correct |
957 ms |
3408 KB |
Output is correct |
16 |
Correct |
1551 ms |
2472 KB |
Output is correct |
17 |
Execution timed out |
7101 ms |
2392 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
3 ms |
2392 KB |
Output is correct |
4 |
Correct |
20 ms |
2496 KB |
Output is correct |
5 |
Correct |
114 ms |
2888 KB |
Output is correct |
6 |
Correct |
970 ms |
3256 KB |
Output is correct |
7 |
Correct |
961 ms |
3192 KB |
Output is correct |
8 |
Correct |
964 ms |
3208 KB |
Output is correct |
9 |
Correct |
965 ms |
3216 KB |
Output is correct |
10 |
Correct |
964 ms |
3244 KB |
Output is correct |
11 |
Correct |
963 ms |
3236 KB |
Output is correct |
12 |
Correct |
986 ms |
3252 KB |
Output is correct |
13 |
Correct |
952 ms |
3236 KB |
Output is correct |
14 |
Correct |
970 ms |
3224 KB |
Output is correct |
15 |
Correct |
957 ms |
3408 KB |
Output is correct |
16 |
Correct |
1551 ms |
2472 KB |
Output is correct |
17 |
Execution timed out |
7101 ms |
2392 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2492 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2488 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2392 KB |
Output is correct |
14 |
Correct |
20 ms |
2496 KB |
Output is correct |
15 |
Correct |
114 ms |
2888 KB |
Output is correct |
16 |
Correct |
970 ms |
3256 KB |
Output is correct |
17 |
Correct |
961 ms |
3192 KB |
Output is correct |
18 |
Correct |
964 ms |
3208 KB |
Output is correct |
19 |
Correct |
965 ms |
3216 KB |
Output is correct |
20 |
Correct |
964 ms |
3244 KB |
Output is correct |
21 |
Correct |
963 ms |
3236 KB |
Output is correct |
22 |
Correct |
986 ms |
3252 KB |
Output is correct |
23 |
Correct |
952 ms |
3236 KB |
Output is correct |
24 |
Correct |
970 ms |
3224 KB |
Output is correct |
25 |
Correct |
957 ms |
3408 KB |
Output is correct |
26 |
Correct |
1551 ms |
2472 KB |
Output is correct |
27 |
Execution timed out |
7101 ms |
2392 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2492 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2488 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2392 KB |
Output is correct |
14 |
Correct |
20 ms |
2496 KB |
Output is correct |
15 |
Correct |
114 ms |
2888 KB |
Output is correct |
16 |
Correct |
970 ms |
3256 KB |
Output is correct |
17 |
Correct |
961 ms |
3192 KB |
Output is correct |
18 |
Correct |
964 ms |
3208 KB |
Output is correct |
19 |
Correct |
965 ms |
3216 KB |
Output is correct |
20 |
Correct |
964 ms |
3244 KB |
Output is correct |
21 |
Correct |
963 ms |
3236 KB |
Output is correct |
22 |
Correct |
986 ms |
3252 KB |
Output is correct |
23 |
Correct |
952 ms |
3236 KB |
Output is correct |
24 |
Correct |
970 ms |
3224 KB |
Output is correct |
25 |
Correct |
957 ms |
3408 KB |
Output is correct |
26 |
Correct |
1551 ms |
2472 KB |
Output is correct |
27 |
Execution timed out |
7101 ms |
2392 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |