因为只能买一次,暴力枚举一下买的衣服的大小。
#include<cstdio> #include<map> #include<algorithm> using namespace std; typedef long long ll; #define fi first #define se second const int maxn = 1e5+5; map<int,int> S; int main() { int T; scanf("%d",&T); for(int k = 1; k <= T; k++){ int N,D,C; scanf("%d%d%d",&N,&D,&C); printf("Case %d: ",k); if(D<=C) { int nn = N; while(nn--) { int t; scanf("%d",&t); } printf("%lld\n",(ll)D*N); continue; } S.clear(); for(int i = 0; i < N; i++){ int t; scanf("%d",&t); S[t]++; } int sum = 0; ll min_cos = (ll)D*N; for(map<int,int>::iterator it = S.begin(); it != S.end(); it++) { sum += it->se; min_cos = min(((ll)C*it->fi-D)*sum+(ll)D*N,min_cos); } printf("%lld\n",min_cos); } return 0; }