Hippo Circus (UVA 13054) by aizu_e
Contest: 3738    RunID: 20174967    Status: Accepted    Date: Sat Oct 14 17:47:52 JST 2017


#include<bits/stdc++.h>
using namespace std;
int main(){
  int c;
  cin>>c;
  for(int k=1;k<=c;k++){
    int n,h,ta,tb,tmp,ans=0;
    cin>>n>>h>>ta>>tb;
    vector<int> hh;
    for(int i=0;i<n;i++){
      cin>>tmp;
      hh.push_back(tmp);
    }
    sort(hh.begin(),hh.end());
    while(hh.size()>1){
      int m,l=0,r=hh.size()-1,k=hh[hh.size()-1];
      while(r-l>1){
	m=(r+l)/2;
	if(hh[m]+k<h)l=m;
	else r=m;
      }
      if(hh[l]+k<h){
	hh.erase(hh.begin()+l);
	ans+=tb;
      }else ans+=ta;
      if(!hh.size())break;
      hh.erase(hh.end()-1);
    }
    cout<<"Case "<<k<<": "<<(ta*2<=tb?n*ta:ans+ta*hh.size())<<endl;
  }
  return 0;
}