#P1909. [NOIP 2016 普及组] 买铅笔

[NOIP 2016 普及组] 买铅笔

Description

Teacher P needs to go to the store to buy nn pencils as gifts for children participating in NOIP. She finds that the store has 33 types of packaging; different packages may contain different numbers of pencils, and their prices may also differ. For fairness, Teacher P decides to buy only one type of package.

The store does not allow opening packages, so Teacher P may need to buy more than nn pencils to have enough gifts for the children.

Now Teacher P wants to know, assuming there is sufficient stock for each package type, what is the minimum amount of money needed to buy at least nn pencils.

Input Format

The first line contains a positive integer nn, indicating the required number of pencils.

The next three lines each describe one type of package with 22 positive integers: the first integer is the number of pencils in that package, and the second integer is the price of that package.

It is guaranteed that all 77 numbers are positive integers not exceeding 1000010000.

Output Format

11 integer, indicating the minimum amount of money Teacher P needs to spend.

57
2 2
50 30
30 27
54
9998
128 233
128 2333
128 666
18407
9999
101 1111
1 9999
1111 9999
89991

Hint

The three package types are:

  • 22-pack, price 22.
  • 5050-pack, price 3030.
  • 3030-pack, price 2727.

Teacher P needs to buy at least 5757 pencils.

If she chooses the first package type, then she needs to buy 2929 packs, totaling 2×29=582 \times 29 = 58 pencils, and the cost is 2×29=582 \times 29 = 58.

In fact, Teacher P will choose the third package type, in which case she needs to buy 22 packs. Although the final number of pencils is more, 30×2=6030 \times 2 = 60, the cost is reduced to 27×2=5427 \times 2 = 54, which is less than the first option.

For the second package type, although the price per pencil is the lowest, to have enough she must buy 22 packs, and the actual cost reaches 30×2=6030 \times 2 = 60, so Teacher P will not choose it.

Therefore, the final output is 5454.

Constraints

It is guaranteed that all 77 numbers are positive integers not exceeding 1000010000.

Subtasks

Subtasks provide characteristics of some testdata. If you find the problem difficult, you can try to solve only part of the testdata.

The data scale and characteristics for each test point are shown in the table below:

In the table above, the meaning of “exact multiple” is: if it is KK, it means the required number of pencils nn is an exact multiple of the number of pencils in each package type (which means you can avoid buying extra pencils).

Three Hack testdata groups were newly added on December 23, 2022.

Translated by ChatGPT 5