Hippo Circus (UVA 13054) by return_zukky
Contest: 3738    RunID: 20173865    Status: Accepted    Date: Sat Oct 14 14:39:40 JST 2017


#include<bits/stdc++.h>
using namespace std;

int h[100005];

int main(){

  int T=1,t;
  
  cin>>t;
  
  while(t--){
    
    int n, H, ta, tb;

    cin>>n>>H>>ta>>tb;

    for(int i=0;i<n;i++) scanf("%d", &h[i]);

    sort(h,h+n);

    int ans=0, l=0, r=n-1;

    while(1){
      
      if(ta*2>tb&&h[l]+h[r]<H){
	ans+=tb;
	l++;
	r--;
      }else{
	ans+=ta;
	r--;
      }

      if(l==r){
	ans+=ta;
	break;
      }
      
      if(l>r) break;
    }
        
    cout<<"Case "<<T++<<": ";
    cout<<ans<<endl;    
  }
  
  return 0;
}