21164_ProblemSolving

2022-5-16 18:18| 发布者: Hocassian| 查看: 45| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-3-89504961552900-Problem List-采集的数据-后羿采集器.html

Pro.ID

21164

Title

Problem Solving

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21164

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    In easier times, Farmer John's cows had no problems. These days, though, they have problems, lots of problems; they have P (1 ≤ P ≤ 300) problems, to be exact. They have quit providing milk and have taken regular jobs like all other good citizens. In fact, on a normal month they make M (1 ≤ M ≤ 1000) money.

    Their problems, however, are so complex they must hire consultants to solve them. Consultants are not free, but they are competent: consultants can solve any problem in a single month. Each consultant demands two payments: one in advance ( 1 ≤ paymentM ) to be paid at the start of the month problem-solving is commenced and one more payment at the start of the month after the problem is solved ( 1 ≤ paymentM ). Thus, each month the cows can spend the money earned during the previous month to pay for consultants. Cows are spendthrifts: they can never save any money from month-to-month; money not used is wasted on cow candy.

    Since the problems to be solved depend on each other, they must be solved mostly in order. For example, problem 3 must be solved before problem 4 or during the same month as problem 4.

    Determine the number of months it takes to solve all of the cows' problems and pay for the solutions.

    输入

    * Line 1 : Two space-separated integers: M and P.

    * Lines 2 ..P+1 : Line i+1 describes problem i with two space-separated integers: Bi and Ai. Bi is the payment to the consult BEFORE the problem is solved; Ai is the payment to the consult AFTER the problem is solved.

    输出

    Description

    In easier times, Farmer John's cows had no problems. These days, though, they have problems, lots of problems; they have P (1 ≤ P ≤ 300) problems, to be exact. They have quit providing milk and have taken regular jobs like all other good citizens. In fact, on a normal month they make M (1 ≤ M ≤ 1000) money.

    Their problems, however, are so complex they must hire consultants to solve them. Consultants are not free, but they are competent: consultants can solve any problem in a single month. Each consultant demands two payments: one in advance ( 1 ≤ paymentM ) to be paid at the start of the month problem-solving is commenced and one more payment at the start of the month after the problem is solved ( 1 ≤ paymentM ). Thus, each month the cows can spend the money earned during the previous month to pay for consultants. Cows are spendthrifts: they can never save any money from month-to-month; money not used is wasted on cow candy.

    Since the problems to be solved depend on each other, they must be solved mostly in order. For example, problem 3 must be solved before problem 4 or during the same month as problem 4.

    Determine the number of months it takes to solve all of the cows' problems and pay for the solutions.

    Input

    * Line 1 : Two space-separated integers: M and P.

    * Lines 2 ..P+1 : Line i+1 describes problem i with two space-separated integers: Bi and Ai. Bi is the payment to the consult BEFORE the problem is solved; Ai is the payment to the consult AFTER the problem is solved.

    Output

    * Line 1 : The number of months it takes to solve and pay for all the cows' problems.

    Sample Input

    100 5
    40 20
    60 20
    30 50
    30 50
    40 40

    Sample Output

    6

    Hint

    Input Details

    The cows make 100 money each month. They have 5 problems to solve, which cost 40, 60, 30, 30, and 40 in advance to solve and then 20, 20, 50, 50, and 40 at the beginning of the month after the problems are solved.

    Output Details

    +------+-------+--------+---------+---------+--------+
    |      | Avail | Probs  | Before  | After   | Candy  |
    |Month | Money | Solved | Payment | Payment | Money  |
    +------+-------+--------+---------+---------+--------+
    | 1    | 0     | -none- | 0       | 0       | 0      |
    | 2    | 100   | 1, 2   | 40+60   | 0       | 0      |
    | 3    | 100   | 3, 4   | 30+30   | 20+20   | 0      |
    | 4    | 100   | -none- | 0       | 50+50   | 0      |
    | 5    | 100   | 5      | 40      | 0       | 60     |
    | 6    | 100   | -none- | 0       | 40      | 60     |
    +------+-------+--------+---------+---------+--------+

    Source

    样例输入

    100 5
    40 20
    60 20
    30 50
    30 50
    40 40

    样例输出

    6

    提示

    Input Details

    The cows make 100 money each month. They have 5 problems to solve, which cost 40, 60, 30, 30, and 40 in advance to solve and then 20, 20, 50, 50, and 40 at the beginning of the month after the problems are solved.

    Output Details

    +------+-------+--------+---------+---------+--------+
    |      | Avail | Probs  | Before  | After   | Candy  |
    |Month | Money | Solved | Payment | Payment | Money  |
    +------+-------+--------+---------+---------+--------+
    | 1    | 0     | -none- | 0       | 0       | 0      |
    | 2    | 100   | 1, 2   | 40+60   | 0       | 0      |
    | 3    | 100   | 3, 4   | 30+30   | 20+20   | 0      |
    | 4    | 100   | -none- | 0       | 50+50   | 0      |
    | 5    | 100   | 5      | 40      | 0       | 60     |
    | 6    | 100   | -none- | 0       | 40      | 60     |
    +------+-------+--------+---------+---------+--------+


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部