QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 256 MB 満点: 100

#6151. Otaku Plan

統計

Since JYY became obsessed with puzzles, he has become a complete shut-in. To solve the problem of food and clothing, JYY has to rely on ordering takeout to make a living.

Problem Statement

There are $N$ types of food in the takeout shop, numbered from 1 to $N$. The $i$-th type of food has a fixed price $P_i$ and a shelf life $S_i$. The $i$-th food will expire after $S_i$ days. JYY will not eat expired food.

For example, if JYY orders a food with a shelf life of 1 day today, he must eat it today or tomorrow; otherwise, the food can no longer be eaten. The shelf life can be 0 days, which means the food must be eaten on the day it is purchased.

JYY currently has $M$ dollars, and every time he orders takeout, he needs to pay an additional delivery fee of $F$ dollars to the delivery person. The delivery person is strong and can instantly bring any number of food items to JYY. JYY wants to know, under the condition that he can eat at least one non-expired meal every day, what is the maximum number of days he can stay at home?

Input

The first line contains three integers $M$, $F$, and $N$.

The next $N$ lines each contain two integers $P_i$ and $S_i$.

Output

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

Examples

Input 1

32 5 2
5 0
10 2

Output 1

3

Note

JYY's optimal strategy is: Day 1: Buy one unit of food 1 and one unit of food 2, and eat one unit of food 1; Day 2: Eat one unit of food 2; Day 3: Buy one unit of food 1 and eat it.

Constraints

  • For 10% of the data, $N = 1$;
  • For 30% of the data, $M, S_i \le 300$;
  • For 60% of the data, $M, S_i \le 300000$;
  • For 100% of the data, $0 \le S_i \le 10^{18}$, $1 \le F, P_i, M \le 10^{18}$, $1 \le N \le 200$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.