Hippo Circus (UVA 13054) by kzyKT
Contest: 3738    RunID: 20173736    Status: Accepted    Date: Sat Oct 14 14:18:18 JST 2017


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

int main() {
  int T,tt=1;
  cin >> T;
  while(T--) {
    ll n,H,x,y;
    cin >> n >> H >> x >> y;
    ll a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a,a+n,greater<ll>());
    deque<ll> que;
    for(int i=0; i<n; i++) que.push_back(a[i]);
    ll ans=0;
    while(!que.empty()) {
      ll c=que.front();que.pop_front();
      if(!que.empty()&&x*2>y&&c+que.back()<H) {
        que.pop_back();
        ans+=y;
      } else ans+=x;
    }
    cout << "Case " << tt++ << ": " << ans << endl;
  }
  return 0;
}