Logo
(追記) (追記ここまで)

27723번 - Karl's shopping 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
12 초 1024 MB85562.500%

문제

Karl is going to spend his holiday in Nothingland. Since there is nothing there, he has to buy all supplies now. At the moment, he is waiting at the checkout counter with a shopping cart full of stuff.

Of course, he has a sufficient amount of money in his wallet. However, he prefers to use alternate means of payment if possible: luncheon vouchers, gift certificates, different types of coupons, etc. What makes the matter complicated is that the use of these items is often limited: e.g., luncheon vouchers can only be used to buy food, and gift certificates are often limited to a certain type of gifts.

You are given the number N of items in Karl’s shopping cart and their prices. You are also given the number M of vouchers in his wallet, together with the information on their allowed use.

When paying for his shopping, Karl may use vouchers for a larger sum than the cost of the things he is buying. It is also possible to split an item’s cost between multiple vouchers and use a voucher to pay for more than one item.

Compute the minimum amount of additional cash money Karl needs to pay for his shopping.

입력

The first line of input file contains an integer T specifying the number of test cases. T blocks follows, each block describes one test case. Each block is preceded by a blank line.

Each block starts with line containing two positive integers N (the number of items) and M (the number of vouchers). The second line contains N numbers Ai, the i-th of them being the price of the i-th item in Karl’s shopping cart. The third line contains M numbers Bi, the i-th of them being the cash value of the i-th voucher Karl has in his wallet. M lines follow. Each line consists of a number Ki (the count of items such that you can pay for them using the i-th voucher) followed by Ki numbers (the numbers of those items; items are numbered from 1 to N).

출력

For each test case output a single number specifying how much cash money Karl needs to pay for his shopping.

제한

Easy (1점)

  • 1 ≤ T ≤ 40
  • 1 ≤ N, M ≤ 100
  • 1 ≤ Ai ≤ 1000
  • 1 ≤ Bi ≤ 1000
  • 0 ≤ Ki ≤ N

Hard (2점)

  • T = 1
  • 1 ≤ N, M ≤ 2000
  • 1 ≤ Ai ≤ 10000
  • 1 ≤ Bi ≤ 10000
  • 0 ≤ Ki ≤ N

예제 입력 1

1
3 2
15 20 10
20 30
3 1 2 3
1 3

예제 출력 1

15

힌트

출처

Contest > Internet Problem Solving Contest > IPSC 2009 K번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /