#P1964. 【mc生存】卖东西

【mc生存】卖东西

Description

lcy0x1 goes to the server’s system shop to sell items.

A player’s backpack has 2121 slots.

Initially, his backpack contains mm different item types (cannot be sold), which occupy mm slots.

He wants to sell nn types of items. For the ii-th type with name stist_i, there are aia_i items, each worth bib_i, and up to cic_i items can be stacked in one slot.

Identical items can be put in the same slot as long as it is not full.

Question: In one run, what is the maximum amount of money he can sell?

Input Format

The first line contains two integers m,nm, n.

Each of the next nn lines contains three integers ai,bi,cia_i, b_i, c_i and a string stist_i.

Output Format

The maximum amount of money ss.

20 3
63 1 64 yinshifen
1 10 1 men
1 1 64 yinshifen
64

Hint

Constraints:

  • 0m210\leq m\leq 21
  • 0n1000\leq n\leq 100
  • 0ai13440\leq a_i\leq 1344
  • 0bi1040\leq b_i\leq 10^4
  • 0<ci640<c_i\leq 64
  • 0<sti<1000<|st_i|<100
  • 0s1060\leq s\leq 10^6

Note: The testdata is strong. Brute-force search scores 00. Please use the bounded knapsack.

Translated by ChatGPT 5