This page is still under construction.

Parts of this page are still being built. What you see may change.

Ampelmännchen

Time limit1sMemory limit256 MB

Summary
For each item pick the West or East version that gives the larger population-weighted happiness total.
Level

Easy2 of 10

Topics
Greedy, Implementation
Solved
No attempts yet

Problem

When two countries unite, each one already has its own version of most everyday things: road signs, pickles, ketchup. If one country simply imposes its version on the other, the result feels less like a union of equals and more like an annexation. Many East Germans saw the German unification that way, and it took them years to identify with the new country. A union that holds takes pieces from both sides.

Sometimes both sides agree that one country's version is better. Everyone liked the East German Ampelmännchen, the little walking figure on the pedestrian traffic signal. The hard case is when each side prefers its own version. Then the two sides trade: "we care a lot about our pickles, so let us keep ours, but your ketchup is almost as good as ours, so we will take yours."

You are given a list of contentious items. For each item you know how much each of the two countries likes each of the two versions, and you know how many people live in each country. Every person feels exactly the like value that their own country reports for the version that was chosen. For each item you pick exactly one of the two versions. Maximize the total happiness summed over all people and all items.

Concretely, if the West's version of an item is chosen, that item adds W⋅Lw,w+E⋅Le,wW \cdot L_{w,w} + E \cdot L_{e,w} to the total. If the East's version is chosen, it adds W⋅Lw,e+E⋅Le,eW \cdot L_{w,e} + E \cdot L_{e,e}.

Input

The first line contains K≥1K \ge 1, the number of data sets in the file. KK data sets follow.

The first line of a data set contains three integers nn, WW, EE. 0≤n≤10000 \le n \le 1000 is the number of contentious items, and 0≤W,E≤100000 \le W, E \le 10000 are the numbers of people living in the West and in the East.

Then come nn lines, each with four integers Lw,wL_{w,w}, Lw,eL_{w,e}, Le,wL_{e,w}, Le,eL_{e,e}, all between 0 and 100. In order they are how much the West likes its own version, how much the West likes the East's version, how much the East likes the West's version, and how much the East likes its own version.

Output

For each data set, print Data Set x: on a line by itself, where xx is the number of the data set counting from 1. On the next line print the maximum total happiness reachable by choosing exactly one version of every item. Print a blank line after each data set.

Examples4

  1. Example 1

    Input
    1
    5 10 15
    7 1 2 6
    0 5 0 5
    7 0 0 6
    4 0 0 2
    1 2 1 0
    
    Expected output
    Data Set 1:
    380
    
  2. Example 2

    Input
    1
    0 0 0
    
    Expected output
    Data Set 1:
    0
    
    
  3. Example 3

    Input
    1
    1 10000 10000
    100 100 100 100
    
    Expected output
    Data Set 1:
    2000000
    
    
  4. Example 4

    Input
    1
    3 7 11
    0 9 9 0
    9 0 0 9
    5 5 5 5
    
    Expected output
    Data Set 1:
    288