Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|

Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |

Language: Problem Solving
Description In easier times, Farmer John's cows had no problems. These days, though, they have problems, lots of problems; they have 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 ≤ 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: B and _{i}A. _{i}B is the payment to the consult BEFORE the problem is solved; _{i}A is the payment to the consult AFTER the problem is solved.
_{i}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
Source |

[Submit] [Go Back] [Status] [Discuss]

All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di

Any problem, Please Contact Administrator