思路:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define lson p << 1
#define rson p << 1 | 1
const int maxn = 1e6 + 5, inf = 1e18, maxm = 4e4 + 5, N = 1e6, base = 397;
// const int mod = 1e9 + 7;
const __int128 mod = 212370440130137957ll;
int a[maxn], b[maxn];
bool vis[maxn];
int n, m;
string s;
struct Node{
int l, r;
};
int add[maxn], pr[maxn];
int calc(int c, int k){
int res = 0;
int v = c % k, u = k - c % k;
int x = c / k;
res = u * (u - 1) / 2 * x * x + v * (v - 1) / 2 * (x + 1) * (x + 1) + u * v * x * (x + 1);
return res;
}
void solve(){
int res = 0;
int q, k;
cin >> n;
int mx = 0;
int b, x;
cin >> b >> x;
for(int i = 1; i <= n; i++){
cin >> a[i];
mx = max(mx, a[i]);
}
for(int i = 1; i <= mx; i++){
add[i] = 0;
pr[i] = 0;
}
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++){
for(int j = 1; j <= a[i]; j++){
pr[j] += calc(a[i], j);
}
add[a[i] + 1] += calc(a[i], a[i]);
}
int other = 0;
for(int i = 1; i <= mx; i++){
other += add[i];
res = max(res, (pr[i] + other) * b - (i - 1) * x);
}
cout << res << '\n';
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
cin >> T;
while (T--)
{
solve();
}
return 0;
}