Hippo Circus (UVA 13054) by ynu_a
Contest: 3738    RunID: 20174035    Status: Accepted    Date: Sat Oct 14 15:05:12 JST 2017


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

int main(){
    int c;
    cin >> c;
    for(int i=1;i<=c;++i){
        int n, H, ta, td;
        cin >> n >> H >> ta >> td;
        vector<int> h;
        for(int j=0;j<n;++j){
            int tmp;
            cin >> tmp;
            h.push_back(tmp);
        }
        if(2 * ta > td){
            sort(h.begin(), h.end());
            int left=0, right=n-1, ans=0;
            while(left < right){
                if(h[right] + h[left] < H){
                    ans += td;
                    right--;
                    left++;
                }else{
                    ans += ta;
                    right--;
                }
            }
            if(left == right)ans += ta;
            printf("Case %d: %d\n",i,ans);
        }else{
            printf("Case %d: %d\n",i,ta*n);
        }
    }

    return 0;
}