#P16307. [蓝桥杯 2026 省 Java/Python 研究生组] 抓取卡牌

[蓝桥杯 2026 省 Java/Python 研究生组] 抓取卡牌

Problem Description

There are nn different types of cards. For the ii-th type, its base value is viv_i, and there are aia_i cards of this type.

You need to choose exactly XX cards from these cards to form your own deck.

For the same type of card, as you choose more of them, the value of later cards will decrease. Specifically, if you have already chosen kk cards of a type with base value vv, then the value of the next card of this type is:

⌊vk+1⌋\left\lfloor \frac{v}{k + 1} \right\rfloor

⌊x⌋\lfloor x \rfloor means taking the floor of xx, i.e., the largest integer that does not exceed xx.

That is:

  • When choosing the 11-st card of this type, its value is ⌊v1⌋=v\left\lfloor \frac{v}{1} \right\rfloor = v;
  • When choosing the 22-nd card, its value is ⌊v2⌋\left\lfloor \frac{v}{2} \right\rfloor;
  • When choosing the 33-rd card, its value is ⌊v3⌋\left\lfloor \frac{v}{3} \right\rfloor;
  • And so on.

For each type of card, you can choose at most aia_i cards.

Now, please compute: when choosing exactly XX cards, what is the maximum total value you can obtain.

Input Format

The input consists of three lines.

The first line contains two integers n,Xn, X, representing the number of card types and the total number of cards that need to be chosen.

The second line contains nn integers v1,v2,…,vnv_1, v_2, \dots, v_n, representing the base value of each card type.

The third line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n, representing how many cards are available for each type.

Output Format

Output one line with one integer, representing the maximum total value.

6 6
1 1 2 3 4 5
1 2 1 2 3 4
18

Hint

Sample Explanation

After expanding the values of all possible single cards, we get:

  • Type 11 can contribute: 11.
  • Type 22 can contribute: 1,01, 0.
  • Type 33 can contribute: 22.
  • Type 44 can contribute: 3,13, 1.
  • Type 55 can contribute: 4,2,14, 2, 1.
  • Type 66 can contribute: 5,2,1,15, 2, 1, 1.

Choose the largest 66 values among them: 5,4,3,2,2,25, 4, 3, 2, 2, 2. Their sum is 5+4+3+2+2+2=185+4+3+2+2+2 = 18, so the answer is 1818.

Constraints and Notes for Test Cases

For 50%50\% of the test cases, 1≤n,X≤50001 \le n, X \le 5000.

For all test cases, it holds that 1≤n≤2×1051 \le n \le 2 \times 10^5, 0≤X,ai≤2×1050 \le X, a_i \le 2 \times 10^5, and 0≤vi≤1090 \le v_i \le 10^9.

It is guaranteed that the total number of cards is at least XX.

Translated by ChatGPT 5