#P16579. [GKS 2016 #A] Clash Royale

    ID: 16552 Type: RemoteJudge 10000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>2016折半搜索 meet in the middleGoogle Kick Start

[GKS 2016 #A] Clash Royale

题目描述

Clash Royale is a real time strategy card game. Each card has an attack power and a level. Each player picks 8 cards to form a battle deck; the total attack power of a deck is the sum of the attack power of each of its cards. Players fight with each other by placing cards from their battle decks into the battle arena. The winner of a battle is rewarded with coins, which can be used to upgrade cards. Upgrading a card increases its attack power.

After days of arena fighting, Little Shawn has accumulated a total of MM coins. He has decided to upgrade some of his cards. Little Shawn has NN cards. The ii-th card can have any level from 1 through KiK_i; the attack power for the jj-th level is Ai,jA_{i,j}. Cards must be upgraded one level at a time; the price to upgrade the ii-th card from level jj to level j+1j+1 costs Ci,jC_{i,j} coins. The ii-th card is currently at level LiL_i before Little Shawn has upgraded any cards.

Little Shawn wants to use some or all of his coins to upgrade cards, and then form a deck of exactly 8 cards, so that the deck's total attack power is as large as possible. Can you help him do this? He can upgrade the same card more than once as long as he can afford it, and he does not have to upgrade every card.

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case starts with 2 integers MM and NN, the number of coins and the number of cards that Little Shawn possesses. Then NN blocks follow. The ii-th block consists of 3 lines describing the ii-th card. The first line contains two integers KiK_i and LiL_i, the maximum possible level and current level of the card. The second line contains KiK_i integers Ai,1,Ai,2,...,Ai,KiA_{i,1}, A_{i,2}, ..., A_{i,K_i}, the attack power of each level. The third line contains Ki1K_i-1 integers Ci,1,Ci,2,...,Ci,Ki1C_{i,1}, C_{i,2}, ..., C_{i,K_i-1}, the number of coins required to upgrade a card that is currently at level 1, 2, ..., Ki1K_i-1.

输出格式

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the maximal possible total attack power of a deck that Little Shawn can form, using the coins that he has.

2
20 8
3 1
1 10 100
1 2
3 1
1 10 100
1 3
3 1
1 10 100
1 4
3 1
1 10 100
1 5
3 1
1 10 100
1 6
3 1
1 10 100
1 7
3 1
1 10 100
1 8
3 1
1 10 100
1 9
30 10
4 1
1 10 100 200
1 2 3
3 1
1 10 100
2 4
3 1
1 10 100
3 6
4 2
1 10 100 200
4 8 16
3 1
1 10 100
5 10
3 1
1 10 100
6 12
3 1
1 10 100
7 14
3 1
1 10 100
8 16
3 1
1 10 100
9 18
3 1
1 10 100
10 20
Case #1: 422
Case #2: 504

提示

In sample case #11, you can upgrade the first 44 cards to level 33, upgrade the 5th and 6th card to level 22, keep the last 22 cards level 11. This will cost you (1+2)+(1+3)+(1+4)+(1+5)+1+1=20(1+2)+(1+3)+(1+4)+(1+5)+1+1=20 coins and the total attack power is 100+100+100+100+10+10+1+1=422100+100+100+100+10+10+1+1=422 which is the maximal possible we can get.

Sample case #22 will only appear in large dataset.

Limits

1T1001 \le T \le 100.

1Ki101 \le K_i \le 10.

1LiKi1 \le L_i \le K_i.

Ai,j<Ai,j+1A_{i,j} < A_{i,j+1}.

Small dataset (Test set 1 - Visible)

1M1,0001 \le M \le 1,000.

N=8N = 8.

1Ai,j1,0001 \le A_{i,j} \le 1,000.

1Ci,j1,0001 \le C_{i,j} \le 1,000.

Large dataset (Test set 2 - Hidden)

1M1,000,000,0001 \le M \le 1,000,000,000.

8N128 \le N \le 12.

1Ai,j1,000,000,0001 \le A_{i,j} \le 1,000,000,000.

1Ci,j1,000,000,0001 \le C_{i,j} \le 1,000,000,000.