```c++ #include <iostream> (30316)#include <vector> #include <cstring> (31637)#include <algorithm> using namespace std; typedef unsigned long long LL; const int N = 200010; LL a[N]; LL mex[N]; LL cnt[N]; int main() { int T; cin >> T; while (T--) { memset(a, 0, sizeof a); memset(mex, 0, sizeof mex); memset(cnt, 0, sizeof cnt); LL n, k, x; scanf("%lld%lld%lld", &n, &k, &x); for (int i = 0; i < n; i++) { scanf("%lld", a + i); cnt[a[i]]++; } LL mx = 0; while (cnt[mx]) mx++; mex[0] = mx; for (int i = 1; i < n; i++) { cnt[a[i - 1]]--; if (cnt[a[i - 1]] == 0) mx = min(mx, a[i - 1]); mex[i] = mx; } LL res = 0x3f3f3f3f; res = res * res; LL sum = 0; for (int i = 0; i < n; i++) { res = min(res, sum + k * mex[i]); sum += x; } res = min(res, sum); cout << res << endl; } return 0; } ```

相关推荐

牛客网
牛客企业服务