Hippo Circus (UVA 13054) by beet1333
Contest: 3738    RunID: 20173996    Status: Accepted    Date: Sat Oct 14 14:57:48 JST 2017


#include<bits/stdc++.h>

using namespace std;

using int64 = long long;

struct BeetAizu
{

  BeetAizu()
  {
  }

  void run()
  {
    int N, H, Ta, Tb;
    int A[100000];
    scanf("%d %d %d %d", &N, &H, &Ta, &Tb);
    for(int i = 0; i < N; i++) scanf("%d", &A[i]);
    sort(A, A + N);

    int64 ret = 0;
    bool v[100000] = {};

    int tail = N - 1;
    for(int i = 0; i < N; i++) {
      if(v[i]) continue;
      while(tail > i && (A[i] + A[tail] >= H || v[tail])) --tail;
      if(tail > i && !v[tail] && 2 * Ta > Tb) ret += Tb, v[tail] = true;
      else ret += Ta;
      v[i] = true;
    }
    printf("%lld\n", ret);
  }
};

int main()
{
  BeetAizu beet;
  int T;
  cin >> T;
  for(int i = 1; i <= T; i++) {
    cout << "Case " << i << ": ";
    beet.run();
  }
}