#P4040. [AHOI2014/JSOI2014] 宅男计划

[AHOI2014/JSOI2014] 宅男计划

Description

There are nn types of food, numbered from 11 to nn. The ii-th type of food has a fixed price pip_i and a shelf life sis_i. The ii-th type expires after sis_i days. JYY will not eat expired food.

For example, if JYY orders a food with a shelf life of 11 day today, then JYY must eat it today or tomorrow; otherwise, this food can no longer be eaten. The shelf life can be 00 days, in which case the food must be eaten on the day of purchase.

JYY currently has mm yuan. Each time he places a takeout order, he must additionally pay a delivery fee of ff yuan.

The delivery person is strong and can instantly bring JYY arbitrarily many portions of food in one order. JYY wants to know, while ensuring that he can eat at least one unexpired takeout meal every day, for how many days at most can he stay at home.

Input Format

The first line contains three integers, representing m,f,nm, f, n.

Lines 22 to (n+1)(n + 1) each contain two integers; in line (i+1)(i + 1), the integers denote the price pip_i and the shelf life sis_i of the ii-th type of food.

Output Format

Output a single integer in one line, representing the maximum number of days JYY can stay at home.

32 5 2
5 0
10 2
3

Hint

Explanation of Sample Input/Output 1

JYY’s best strategy is:

  • On day 1, buy one portion of food 11 and one portion of food 22, and eat one portion of food 11.
  • On day 2, eat one portion of food 22.
  • On day 3, buy one portion of food 11 and eat it.

Constraints

For all test points, it is guaranteed that 1n2001 \leq n \leq 200, 0si10180 \leq s_i \leq 10^{18}, 1f,pi,m10181 \leq f, p_i, m \leq 10^{18}.

Translated by ChatGPT 5