Submission #602963

#TimeUsernameProblemLanguageResultExecution timeMemory
602963cadmiumskyDiversity (CEOI21_diversity)C++14
0 / 100
1 ms340 KiB
#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'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...