{"trustable":false,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003ca href\u003d\"https://codeforces.com/problemset/problem/1989/D\"\u003eProblem Link\u003c/a\u003e"}},{"title":"","value":{"format":"HTML","content":"\u003cp\u003eYou are playing a famous computer game (that just works) where you have various skills you can level up. Today, you focused on the \"Smithing\" skill. Your tactic is obvious: forging weapons from ingots and then melting them back to return the materials partially. For simplicity, every time you create an item, you get $$$1$$$ experience point, and every time you melt an item, you also get $$$1$$$ experience point.\u003c/p\u003e\u003cp\u003eThere are $$$n$$$ classes of weapons you can forge and $$$m$$$ types of metal ingots.\u003c/p\u003e\u003cp\u003eYou can create one weapon of the $$$i$$$-th class, spending $$$a_i$$$ ingots of metal of \u003cspan class\u003d\"tex-font-style-it\"\u003ethe same type\u003c/span\u003e. Melting a weapon of the $$$i$$$-th class (which you crafted earlier) returns you $$$b_i$$$ ingots of the type of metal \u003cspan class\u003d\"tex-font-style-it\"\u003eit was made of\u003c/span\u003e.\u003c/p\u003e\u003cp\u003eYou have $$$c_j$$$ metal ingots of the $$$j$$$-th type, and you know that you can craft a weapon of any class from any metal type. Each combination of a weapon class and a metal type can be used any number of times.\u003c/p\u003e\u003cp\u003eWhat is the maximum total amount of experience you can earn by crafting and melting weapons?\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 10^6$$$)\u0026nbsp;— the number of weapon classes and metal types.\u003c/p\u003e\u003cp\u003eThe second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 10^6$$$), where $$$a_i$$$ is the number of ingots you need to forge one weapon of the $$$i$$$-th class.\u003c/p\u003e\u003cp\u003eThe third line contains $$$n$$$ integers $$$b_1, b_2, \\dots, b_n$$$ ($$$0 \\le b_i \u0026lt; a_i$$$), where $$$b_i$$$ is the number of ingots you return by melting one weapon of the $$$i$$$-th class you forged earlier.\u003c/p\u003e\u003cp\u003eThe fourth line contains $$$m$$$ integers $$$c_1, c_2, \\dots, c_m$$$ ($$$1 \\le c_j \\le 10^9$$$)\u0026nbsp;— the number of ingots you have of the corresponding metal type.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003ePrint one integer\u0026nbsp;— the maximum total experience points you can gain by repeatedly forging and melting weapons.\u003c/p\u003e"}},{"title":"Examples","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 3\n9 6 7 5 5\n8 4 5 1 2\n10 4 7\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e12\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"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\u003e3 4\n10 20 20\n0 0 0\n9 10 19 20\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e8\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"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\u003e1 5\n3\n1\n1000000000 1000000000 1000000000 1000000000 1000000000\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e4999999990\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eIn the first example, you can do the following: \u003c/p\u003e\u003col\u003e \u003cli\u003e craft one weapon of the $$$1$$$-st class from the $$$1$$$-st type of metal, spending $$$9$$$ ingots; \u003c/li\u003e\u003cli\u003e melt that weapon, returning $$$8$$$ ingots of the $$$1$$$-st metal type; \u003c/li\u003e\u003cli\u003e again, craft and melt one weapon of the $$$1$$$-st class from the $$$1$$$-st metal type; \u003c/li\u003e\u003cli\u003e craft and melt one weapon of the $$$3$$$-rd class from the $$$1$$$-st metal type; \u003c/li\u003e\u003cli\u003e craft and melt one weapon of the $$$3$$$-rd class from the $$$3$$$-rd metal type; \u003c/li\u003e\u003cli\u003e craft and melt one weapon of the $$$4$$$-th class from the $$$1$$$-st metal type; \u003c/li\u003e\u003cli\u003e craft and melt one weapon of the $$$5$$$-th class from the $$$3$$$-rd metal type; \u003c/li\u003e\u003c/ol\u003e In the end you\u0027ll have $$$c \u003d [2, 4, 2]$$$ ingots left. In total, you\u0027ve crafted $$$6$$$ weapons and melted $$$6$$$ weapons, gaining $$$12$$$ experience points in total."}}]}