This page is still under construction.

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

Quest of Merchant

Time limit2sMemory limit512 MB

Summary
Given up to 7 cities on a grid, goods with weights and prices, a weight limit W, and a time limit T, find the maximum profit from trips between the market and cities.
Level

Medium7 of 10

Topics
Dynamic programming, Bit manipulation, Greedy, Implementation
Solved
No attempts yet

Problem

Training is essential to get a good result at the ICPC. The rabbit wants to win at the ICPC, so it decided to train again today.

Today's training is to run around the city trading, and gain the power of commerce.

For future training as well, the rabbit wants to earn as much money as possible.

This world has roads running east, west, north, and south at equal intervals, forming a grid. The only market is at position (0, 0), and cities have x and y coordinates (points with integer coordinates correspond to intersections). The rabbit can move only along roads, and moving between adjacent intersections takes 1 minute. Some intersections have cities. In trade, the rabbit buys goods at a city and sells them at the market, earning the difference in price.

The rabbit starts with enough money, so it never happens that it cannot buy goods because of a lack of money. However, each good has a weight, and the rabbit can carry only goods whose total weight is at most W at the same time. Therefore, it repeats going to a city to stock up on goods and returning to the market. Depending on the case, it may buy goods at multiple cities before returning to the market.

Buying goods at a city and selling goods at the market are both instantaneous. Also, goods at a city never run out, and the rabbit can buy infinitely many.

The rabbit has compiled data on the name, weight per unit, and selling price of each good it plans to trade, and on the x coordinate, y coordinate, and the names and prices of goods sold at each city. The rabbit is now at (0, 0), where the market is. It wants to use a program to find out how much it can earn within the time limit of T minutes.

Input

N M W T
S1 V1 P1
 ...
SM VM PM
L1 X1 Y1
R1,1 Q1,1
  ...
R1,L1 Q1,L1
 ...
LN XN YN
RN,1 QN,1
  ...
RN,LN QN,LN

N is the number of cities, and M is the number of kinds of goods. S**i, V**i, P**i (1 ≤ i ≤ M) are the name, weight per unit, and selling price per unit of the i-th good. Cities are represented by integers from 1 to N. L**j, X**j, Y**j (1 ≤ j ≤ N) are the number of kinds of goods sold at city j, the x coordinate of city j, and the y coordinate of city j. R**j,k, Q**j,k (1 ≤ j ≤ N, 1 ≤ k ≤ L**j) are the name and price of the k-th good sold at city j.

The following hold: 1 ≤ N ≤ 7, 1 ≤ M ≤ 7, 1 ≤ W ≤ 10,000, 1 ≤ T ≤ 10,000, 1 ≤ V**i ≤ W, 1 ≤ P**i ≤ 10,000, 1 ≤ L**j ≤ M, -10,000 ≤ X**j ≤ 10,000, -10,000 ≤ Y**j ≤ 10,000, 1 ≤ Q**j, k ≤ 10,000. The name of a good is a string of lowercase English letters with length between 1 and 7. All other values are integers. All S**i are distinct. The pair (X**j, Y**j) never appears more than once, and (X**j, Y**j) = (0, 0) never holds. For each j, all R**j, k are distinct, and each R**j, k matches some S**i.

Output

Print the maximum profit the rabbit can obtain in one line.

Examples2

  1. Example 1

    Input
    2 2 100 20
    alfalfa 10 10
    carrot 5 10
    1 1 6
    carrot 4
    1 -3 0
    alfalfa 5
    
    Expected output
    170
    
  2. Example 2

    Input
    2 3 100 20
    vim 10 10
    emacs 5 10
    vstudio 65 100
    2 1 6
    emacs 4
    vstudio 13
    3 -3 0
    vim 5
    emacs 9
    vstudio 62
    
    Expected output
    183