思路:枚举所有可能即可,分别计算往下减n个y所对应的结果,取最小值即可

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=100010;

int n,p,x,q,y;

void solve(){
	vector<int> v(n);
	int sum = 0;
	for(int i = 0; i < n; i ++){
		cin >> v[i];
		sum += v[i];
	}
	int ans = 1e18;
	for(int i = 0; i < n; i ++){
		int sum1 = sum - y * i;
		int ans1 = i * q;
		ans1 +=  ((sum1 / n + 1) * n - sum1) % n * p;
		//把往上浮动的部分计算出来,同时%n防止整层浮动、
		//例如如果sum1 = 9,n = 3那么计算结果就是3,实际应该是0才对
		ans = min(ans,ans1);
	}
	cout << ans;
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin >> n >> p >> x >> q >> y;
	solve();
	return 0;
}