{"trustable":false,"sections":[{"title":"题目大意","value":{"format":"HTML","content":"比较好的时候,奶牛没有问题。但是现在,他们有很多问题;它们有P(1)≤ P≤ 问题。他们已经停止提供牛奶,并像所有其他好公民一样从事正规工作。事实上,在一个正常的月份,他们赚了M(1)≤ M≤ 1000)美元。\n然而,他们的问题如此复杂,必须聘请顾问来解决。顾问不是免费的,但他们有能力:顾问可以在一个月内解决任何问题。每位顾问要求两次付款:一次预付(1≤ 付款≤ M) 在月初支付问题解决开始,在问题解决后的月初再支付一次(1≤ 付款≤ M) 。因此,奶牛每个月都可以用上个月赚来的钱来支付顾问费用。牛是挥霍无度的人:它们从不每月储蓄一分钱;没用的钱都浪费在买牛奶糖上了。\n由于要解决的问题相互依赖,因此必须按顺序解决它们。例如,问题3必须在问题4之前或与问题4在同一个月内解决。\n确定解决奶牛所有问题所需的月数,并支付解决方案的费用。"}},{"title":"输入格式","value":{"format":"HTML","content":"第1行:两个空格分隔的整数:M和P。\n第2..P+1行:第i+1行用两个空格分隔的整数描述问题i:Bi和Ai。Bi是在问题解决之前向咨询公司支付的费用;Ai是问题解决后向咨询公司支付的费用。"}},{"title":"输出格式","value":{"format":"HTML","content":"第1行:解决和支付所有奶牛问题所需的月数。"}},{"title":"样例输入","value":{"format":"HTML","content":"\u003cpre class\u003d\"sio\"\u003e100 5\n40 20\n60 20\n30 50\n30 50\n40 40\u003c/pre\u003e"}},{"title":"样例输出","value":{"format":"HTML","content":"\u003cpre class\u003d\"sio\"\u003e6\u003c/pre\u003e"}},{"title":"提示","value":{"format":"HTML","content":"\u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\u003cpre\u003e\u003cp\u003e+------+-------+--------+---------+---------+--------+\u003cbr\u003e|\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; | Avail | Probs\u0026nbsp; | Before\u0026nbsp; | After\u0026nbsp;\u0026nbsp; | Candy\u0026nbsp; |\u003cbr\u003e|Month | Money | Solved | Payment | Payment | Money\u0026nbsp; |\u003cbr\u003e+------+-------+--------+---------+---------+--------+\u003cbr\u003e| 1\u0026nbsp;\u0026nbsp;\u0026nbsp; | 0\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; | -none- | 0\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; | 0\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; | 0\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; |\u003cbr\u003e| 2\u0026nbsp;\u0026nbsp;\u0026nbsp; | 100\u0026nbsp;\u0026nbsp; | 1, 2\u0026nbsp;\u0026nbsp; | 40+60\u0026nbsp;\u0026nbsp; | 0\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; | 0\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; |\u003cbr\u003e| 3\u0026nbsp;\u0026nbsp;\u0026nbsp; | 100\u0026nbsp;\u0026nbsp; | 3, 4\u0026nbsp;\u0026nbsp; | 30+30\u0026nbsp;\u0026nbsp; | 20+20\u0026nbsp;\u0026nbsp; | 0\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; |\u003cbr\u003e| 4\u0026nbsp;\u0026nbsp;\u0026nbsp; | 100\u0026nbsp;\u0026nbsp; | -none- | 0\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; | 50+50\u0026nbsp;\u0026nbsp; | 0\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; |\u003cbr\u003e| 5\u0026nbsp;\u0026nbsp;\u0026nbsp; | 100\u0026nbsp;\u0026nbsp; | 5\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; | 40\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; | 0\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; | 60\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; |\u003cbr\u003e| 6\u0026nbsp;\u0026nbsp;\u0026nbsp; | 100\u0026nbsp;\u0026nbsp; | -none- | 0\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; | 40\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; | 60\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; | \u003cbr\u003e+------+-------+--------+---------+---------+--------+\u003c/p\u003e\u003c/pre\u003e\u003c/div\u003e"}}]}