CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!)- Make It Permutation

发布时间 2023-04-02 19:30:23作者: zhujio

题目链接:Problem - C - Codeforces

 

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--)
    {
        ll n1, c, d;
        cin >> n1 >> c >> d;
        ll ans = 0;
        vector<ll>vec;
        map<ll, int>mp;
        for (int i = 1; i <= n1; i++)
        {
            ll x;
            cin >> x;
            if (!mp[x]) {
                vec.push_back(x);
                mp[x] = 1;
            }
            else ans += c;
        }
        sort(vec.begin(), vec.end());
        int n = vec.size();
        ll maxn = vec[n - 1];
        ll ans1 = LLONG_MAX;
        for (int i = 0; i < n; i++)
        {
            ll res = (vec[i] - 1 - i) * d + (n - i - 1) * c;
            ans1 = min(ans1, res);
        }
        ll ans2 = n1 * c + d;
        if (mp[1])ans2 = (n1 - 1) * c;
        cout << min(ans1+ans,ans2) << endl;
    }
    return 0;
}