#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int nmax = 3e5 + 5;
int freq[nmax];
static ll solve(vector<int> val) {
ll total = 0;
for(auto x : val)
total += (ll)x * (x + 1) / 2;
ll sum = 0, int1 = 0;
for(auto x : val) {
int1 += sum;
total += (ll)x * (int1 + sum);
sum += x;
}
return total;
}
int main() {
int n, q;
cin >> n >> q;
for(int i = 0, x; i < n; i++) {
cin >> x;
freq[x]++;
}
vector<int> val;
for(auto x : freq)
if(x != 0)
val.push_back(x);
sort(val.begin(), val.end());
ll cst = solve(val);
for(int i = 1; i < n; i++) {
reverse(val.end() - i, val.end());
cst = min(cst, solve(val));
reverse(val.end() - i, val.end());
}
cout << cst << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |