| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 (추가 시간 없음) | 1024 MB | 0 | 0 | 0 | 0.000% |
You’ve decided to get rid of your Trading Card Game (TCG) collection. The possible financial activities are as follows:
Given a list of cards, including their card shop cost and whether you own them, and a list of collection sets and the value Jeremy will pay for those sets, determine the maximum amount of money you can earn. This is done by buying from (and/or selling to) the card shop and selling the sets to Jeremy. Note that you choose what to buy from (and/or sell to) the card shop and what to sell to Jeremy. Your earning will be: (cards sold to the shop) + (sets sold to Jeremy) – (cards bought from the shop)
The first input line contains an integer, n (1 ≤ n ≤ 50), representing the number of cards. Each of the next n input lines contains two integers: vi (1 ≤ vi ≤ 10000), representing the Bearimy card value, and hi (0 ≤ hi ≤ 1), representing whether you currently own the card (hi = 1) or not (hi = 0). The cards are provided in the order of indices (1-indexed).
Following the individual card specification will be the description for the collection sets. The first input line in this section contains an integer, m (1 ≤ m ≤ 50), representing the number of sets. The set descriptions follow, each set consisting of two consecutive input lines. The first line of each set description contains two integers: cj (1 ≤ cj ≤ n), representing the number of cards in the set, and wj (1 ≤ wj ≤ 10000), representing the value of the set. The second input line of each set description contains cj distinct positive integers between 1 and n; these values represent the indices (1-indexed) of the cards that belong to the set.
Print a single integer, P, representing the maximum profit that can be earned by buying and selling cards with Bearimy and selling collection sets to Jeremy.
3 2 0 13 1 15 1 1 3 6 1 2 3
28
3 2 0 13 1 15 1 1 3 600 1 2 3
598
4 7 1 3 0 2 1 1 0 3 4 4 1 2 3 4 2 4 2 3 2 4 3 4
11