Submission #602963

# Submission time Handle Problem Language Result Execution time Memory
602963 2022-07-23T13:28:39 Z cadmiumsky Diversity (CEOI21_diversity) C++14
0 / 100
1 ms 340 KB
#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 time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -