1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| #include <bits/stdc++.h> #define all(vec) vec.begin(),vec.end() #define pb push_back #define EB emplace_back #define EM emplace #define FI first #define SE second #define SZ(a) ((int) a.size()) #define FOR(i, a, b) for (long long i = (a); i <= (b); ++i) #define ROF(i, a, b) for (long long i = (a); i >= (b); --i) #define debug(var) cerr << #var <<":"<<var<<"\n"; #define cend cerr<<"-----------\n" #define lson(var) (var<<1) #define rson(var) ((var<<1)+1) #define fsp(x) fixed<<setprecision(x)
using namespace std;
using ll = long long;using ull = unsigned long long; using DB=double;using LD=long double;
using pdd = pair<DB,DB>;using plb = pair<ll,bool>; using pll = pair<ll,ll>;using vll=vector<ll>;using vb=vector<bool>; using tll = tuple<ll,ll,ll>; using vpll = vector<pll>;using vtll = vector<tll>; using arr3 = array<ll,3> ;using arr2 = array<ll,2>; constexpr ll MAXN=(ll)1e6+10,INF=(ll)1e17+9; constexpr ll mod=(ll)1e9+7; constexpr double eps=1e-8;const double pi=acos(-1.0); ll N,M,Q,X,K,T,lT,Y,Z;
inline void __(); signed main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin>>lT; while(lT--) __(); return 0; }
inline void __(){ cin>>N>>X>>Y>>Z; vll P(N),cnt(N+5); FOR(i,0,N-1){ cin>>P[i]; ++cnt[P[i]]; } if(N==1){ cout<<X<<"\n"; return; } sort(all(P)); vll diff(N+5); ll jichu=0; FOR(i,1,N-1){ if(P[i]==P[i-1]){ jichu+=Y; }else{ jichu+=X; } } jichu+=X; FOR(i,1,N){ if(cnt[i]==0) continue; diff[cnt[i]+1]-=1; diff[1]+=1; } vll Sum(N+5); FOR(i,1,N){ Sum[i]=Sum[i-1]+diff[i]; } ll ans=jichu;ll lans=jichu; FOR(i,2,N){ if(Sum[i]<=1) break; lans+=(Sum[i]-1)*X; lans-=Sum[i]*Y; lans+=Z; ans=max(lans,ans); } cout<<ans<<"\n"; }
|