{"trustable":false,"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":"MD","content":"总所周知,LYD是一位富豪。他最近想花恰好S元购置一台电脑,而他想让他的钱包瘦瘦身,于是他决定用尽可能多的钞票去凑这S元钱。\n举个栗子,如果他需要花18元,并且他有2张10元钞票,4张5元钞票和8张1元钞票,那么他会花掉2张5元和8张1元。由于LYD太壕了,他需要你的帮助。"}},{"title":"Input","value":{"format":"MD","content":"\n第一行包含一个整数T,代表测试数据组数(1\u003c\u003dT\u003c\u003d20000)。\n每组数据包含11个整数S,a1,a5,a10,a20,a50,a100,a200,a500,a1000,a2000,其中S代表电脑价钱,ai代表他持有i元钞票的数量(0\u003c\u003dS\u003c\u003d1e9,0\u003c\u003dai\u003c\u003d1e5)。\n"}},{"title":"Output","value":{"format":"MD","content":"每组数据输出花恰好S元钱的最多钞票数,如果LYD无法凑齐恰好S元,则输出-1。"}},{"title":"Sample Input","value":{"format":"MD","content":"\u003cpre\u003e3\n17 8 4 2 0 0 0 0 0 0 0\n100 99 0 0 0 0 0 0 0 0 0\n2015 9 8 7 6 5 4 3 2 1 0\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"MD","content":"\u003cpre\u003e9\n-1\n36\u003c/pre\u003e"}}]}