参考了佬的c题题解思路,感觉很巧妙,记录一下
https://zhuanlan.zhihu.com/p/618685370
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N= 2 * 100010;
int a[N];
void solve()
{
int n,c,d;
cin >> n >> c >> d;
set<int> se;
int sh = 0;//去重花费
for(int i=1; i <= n;i ++) {
cin >> a[i];
}
int tp = c*n + d;//特判花费
sort(a + 1,a + 1 + n);
int n1 = unique(a + 1, a + 1 + n) - (a + 1);//返回值是去重之后的尾地址
sh = c*(n-n1);//重复的个数就是n-n1,去重代价*c
int cnt = 1e18;
n = n1;
for(int i = 1; i <= n; i ++){
cnt =min(cnt, (n-i)*c + (a[i]-i)*d);
}
tp = min(sh+cnt,tp);
cout << tp << '\n';
}
signed main() {
int T;
cin >> T;
while(T --)
solve();
return 0;
}
标签:Rated,int,CodeTON,long,Prizes,n1,Div
From: https://www.cnblogs.com/neko-yingying/p/17285745.html