루미 알고리즘

#1297플래티넘Buying Books

PO 2010 결선코딩영어 원문이 문제가 어렵다면 — 배우는 순서 보기

영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)

Problem

You are going to buy N books of different kinds (numbered from 1 to N), and are currently checking the different Internet book stores for prices. Each book is sold by at least one book store, and can vary in prices between the different stores. Furthermore, each book store incurs a postage fee if you order from it. Postage may vary between the various book stores, but it is always the same for a book store no matter how many books you decide to order. Compute the smallest amount of money you need to pay for all the books. You may order any number of books from any number of the book stores.

Input

The first line contains two integers N (1 ≤ N ≤ 100), the number of books to buy, and M (1 ≤ M ≤ 15), the number of book shops.

Each book shop is then described in the input. A book shop is described first by two integers denoting the number of books K (of the ones you are going to buy) present in the book shop, and the postage fee for the shop. The next K lines each contains two integers: the number of a book present in the book store, and its price.

All prices and the postage fee are in whole Swedish crowns, and do not exceed 10000. The book prices are always positive, but the postage fee can be free in some stores.

Output

The program should output the smallest amount that the books cost, including the postage fee of all shops you choose to purchase from.

Points

Your solution will be tested on several test case groups. To get the points for a group, it must pass all the test cases in the group.

GroupPoint valueConstraints
130M=2
270No additional constraints.

예제

예제 1

입력
7 4
4 9
1 28
6 45
3 49
4 108
7 49
1 26
2 179
3 54
4 99
5 129
6 45
7 244
5 20
7 249
2 184
5 133
4 109
6 42
1 0
6 43
출력
822

출처 표기

출처: Programmeringsolympiaden 2010년 결선 · 원문 페이지 · 이용 조건 CC BY-SA · LaTeX 원문을 화면용 글로 옮겼습니다(수식·표의 모양이 다를 수 있습니다). 내용은 고치지 않았습니다.

크리에이티브 커먼즈 저작자표시-동일조건변경허락.

문제 출처: 한국정보올림피아드(KOI) (CC BY-NC-SA 4.0) · International Olympiad in Informatics (IOI) (CC BY) · Centre for Education in Mathematics and Computing (CEMC), University of Waterloo (CC BY-NC 4.0) · Programmeringsolympiaden (CC BY-SA) · CSES Problem Set (Antti Laaksonen) (CC BY-NC-SA 4.0). 루미 알고리즘은 위 단체들과 관계없는 별도의 서비스이며, 자료는 원문 그대로 싣습니다. 문제마다 출처와 이용 조건을 따로 표기합니다.