Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <stdio.h>
- using namespace std;
- #define int long long
- void solve();
- signed main () {
- // cout << fixed << setprecision(1);
- ios_base::sync_with_stdio(false);
- cin.tie(0); cout.tie(0);
- #ifdef LOCAL
- freopen("input.txt", "r", stdin);
- #endif
- int t = 1;
- // cin >> t;
- int tt = t;
- while (t--) {
- solve();
- }
- return 0;
- }
- const int N = 8005;
- int cnt[N] = {0};
- int n, k;
- void solve() {
- cin >> n >> k;
- for (int i = 1; i <= n; ++i) {
- int x;
- cin >> x;
- cnt[x]++;
- }
- sort(cnt + 1, cnt + k + 1);
- int mn = 1e18;
- for (int i = 0; i <= k; i += 2) {
- int mx = -1e18;
- int rides = 0;
- for (int j = 1; j <= i; j += 1) {
- mx = max(mx, cnt[j] + cnt[i - j + 1]);
- if (j < i - j + 1)
- ++rides;
- }
- for (int j = i + 1; j <= k; j += 1)
- mx = max(mx, cnt[j]), ++rides;
- mn = min(mn, mx * rides);
- }
- cout << mn;
- }
Add Comment
Please, Sign In to add comment