#include <bits/stdc++.h>
using namespace std;
string abc = "abcdefghijklmnopqrstuvwxyz";
#define int long long
int m = 1003;
void solve(){
int n, qq;
cin >> n >> qq;
// vector<int> v(n);
vector<int> a(m, 0);
int r;
int sz = 0;
for(int i = 0; i < n; i++){
cin >> r;
if(a[r]==0) sz++;
a[r]++;
}
cin >> qq >> qq;
vector<int> w, v(sz);
for(int i = 0; i < m; i++){
if(a[i] != 0){
w.push_back(a[i]);
}
}
sort(w.rbegin(), w.rend());
int st = sz/2;
v[st]=w[0];
st--;
int res = 2;
for(int i = 1; i < sz; i++){
v[st]=w[i];
if(i%2 == 0) st-=res;
else st+=res;
res++;
}
int ans = 0;
n = v.size();
for(int i = 0; i < n; i++){
ans+=v[i]*(v[i]+1)/2;
}
queue<int> q;
int cur = 0;
res = 0;
for(int i = 1; i < n; i++){
cur+=(i+1)*v[i];
res+=v[i];
q.push(v[i]);
}
for(int i = 0; i < n-1; i++){
ans+=v[i]*cur;
int a = q.front();
cur-=res;
cur-=a;
res-=a;
}
cout << ans << endl;
}
signed main(){
int t = 1;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |