{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003e作为斗地主的粉丝,WYJ非常喜欢收集扑克牌。\u003cbr\u003e一天,MJF拿起一叠牌对他说:让我们玩个游戏,如果你赢了,这些牌就都归你了。MJF随机地把这些牌分成$n$堆,排成一排,并给每一堆牌设定一个值,称为“惩罚值”。\u003cbr\u003e在游戏开始之前,WYJ可以任意次数地将最前面的一堆移动到最后。\u003cbr\u003e之后,WYJ逐个拿起每一堆牌,每次需要将当前堆的所有牌移到手中并翻面,然后翻开一些牌,翻开的牌数等于$penalty value$。\u003cbr\u003e如果在某一时刻,他手中翻面的牌数少于$penalty value$,游戏就结束了。WYJ可以获得他手中的所有牌(无论是正面还是反面)。\u003cbr\u003e你的任务是帮助WYJ最大化最终可以获得的牌数。因此,他需要决定在游戏开始前将多少堆牌移动到最后。你能帮他找到答案吗?\u003cbr\u003eMJF还保证所有“惩罚值”的总和正好等于所有牌的数量。\u003cbr\u003e\u003c/div\u003e"}},{"title":"输入","value":{"format":"HTML","content":"有大约$10$个测试用例,以EOF结尾。\u003cbr\u003e对于每个测试用例:\u003cbr\u003e第一行是一个整数$n$($1\\leq n\\leq 10^6$),表示$n$堆牌;\u003cbr\u003e接下来一行包含$n$个整数,第$i$$th$个整数$a_i$($0\\leq ai\\leq 1000$)表示第$a_i$堆牌有$i$张牌;\\\\然后第三行也包含$n$个整数,第$i$$th$个整数$b_i$($1\\leq bi\\leq 1000$)表示第$i$堆牌的“惩罚值”为$b_i$。\u003cbr\u003e"}},{"title":"输出","value":{"format":"HTML","content":"对于每个测试用例,只需输出一个整数,表示WYJ在游戏开始前需要移动的堆数。如果有多个解决方案,请输出最小的一个。\u003cbr\u003e"}},{"title":"样例","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e5\r\n4 6 2 8 4\r\n1 5 7 9 2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e4\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}},{"title":"提示","value":{"format":"HTML","content":"\u003cbr\u003e\u003cpre\u003e\u003cbr\u003eFor the sample input:\u003cbr\u003e\u003cbr\u003e+ If WYJ doesn\u0027t move the cards pile, when the game starts the state of cards is:\u003cbr\u003e\u0026nbsp;\u0026nbsp;4 6 2 8 4\u003cbr\u003e\u0026nbsp;\u0026nbsp;1 5 7 9 2\u003cbr\u003eWYJ can take the first three piles of cards, and during the process, the number of face-up cards is 4-1+6-5+2-7. Then he can\u0027t pay the the \"penalty value\" of the third pile, the game ends. WYJ will get 12 cards.\u003cbr\u003e+ If WYJ move the first four piles of cards to the end, when the game starts the state of cards is:\u003cbr\u003e\u0026nbsp;\u0026nbsp;4 4 6 2 8\u003cbr\u003e\u0026nbsp;\u0026nbsp;2 1 5 7 9\u003cbr\u003eWYJ can take all the five piles of cards, and during the process, the number of face-up cards is 4-2+4-1+6-5+2-7+8-9. Then he takes all cards, the game ends. WYJ will get 24 cards.\u003cbr\u003e\u003cbr\u003eIt can be improved that the answer is 4.\u003cbr\u003e\u003cbr\u003e**huge input, please use fastIO.**\u003cbr\u003e\u003c/pre\u003e\u003cbr\u003e"}}]}