Hippo Circus (UVA 13054) by UKUNICHIA
Contest: 3738    RunID: 20173753    Status: Accepted    Date: Sat Oct 14 14:20:31 JST 2017


#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  Int T;
  cin>>T;
  for(Int t=1;t<=T;t++){
    cout<<"Case "<<t<<": ";
    Int n,h,Ta,Td;
    cin>>n>>h>>Ta>>Td;
    
    vector<int> A(n);
    for(Int i=0;i<n;i++) cin>>A[i];
    sort(A.begin(),A.end());
    Int num = 0;
    Int a = 0,b = n-1;
    while(1){
      if(a >= b) break;
      if(A[a] + A[b] < h ) a++,b--,num++;
      else b--;
    }
    Int ans = 1LL<<55;
    for(Int i=0;i<=num;i++) ans = min(ans,Td*i + Ta*(n-2*i));
    cout<<ans<<endl;    
  }
  return 0;
}