Less Time, More Profit

아직 제출이 없습니다시간 제한1초메모리 제한256 MB

문제

The city planners have plans to build NN plants in the city which has MM shops. Each of the plants can be either built or left in the planning stage.

Each shop requires products from some set of plants to operate. If all plants required by shop jj are built, the shop will make an instant one-time profit of pro_j\mathit{pro}\_j units. Once a plant is built, it will produce enough product to support all shops which depend on it.

Building ii-th plant needs investment of pay_i\mathit{pay}\_i units, and it takes t_it\_i days. Two or more plants can be built simultaneously, so that the time for building multiple plants is the maximum of their building times t_it\_i.

The city planners have enough resources to build all plants, but they want to make a net profit. Specifically, they want to select and build a subset of plants such that the total profit of the shops served minus the total cost of the plants built is at least LL units, or find out that it is impossible.

First, find the least possible number of days tt such that it is possible to make a profit of at least LL units in tt days. After that, find the highest possible profit pp you can make in tt days.

입력

The first line of input contains three integers NN, MM and LL: the number of possible plants, the number of shops and the required profit (1N,M2001 \le N, M \le 200, 1L1091 \le L \le 10^9).

Then follow NN lines. Each of them describes a plant and contains two integers pay_i\mathit{pay}\_i and t_it\_i: the investment and building time of ii-th plant (1pay_i31041 \le \mathit{pay}\_i \le 3 \cdot 10^4, 1t_i1091 \le t\_i \le 10^9).

After that, MM lines follow. Each of them describes a shop and starts with an integer profit pro_j\mathit{pro}\_j (1pro_j1.21051 \le \mathit{pro}\_j \le 1.2 \cdot 10^5). Then goes an integer k_jk\_j which is the number of plants required for shop jj to operate (0k_jN0 \le k\_j \le N). It is followed by k_jk\_j pairwise distinct integers plant_j,1\mathit{plant}\_{j, 1}, plant_j,2\mathit{plant}\_{j, 2}, \ldots, plant_j,k_j\mathit{plant}\_{j, k\_j} which are the indices of plants required for shop jj to operate (1plant_j,rN1 \le \mathit{plant}\_{j, r} \le N).

출력

If the required plan exists, print two integers tt and pp: tt must be the least number of days in which it is possible to make a profit of at least LL units, and pp must be the maximum profit that can be made in tt days.

If a plan which makes a profit of at least LL units does not exist, print "impossible".