{"raw_statement":[{"iden":"problem statement","content":"There are $N$ kinds of snacks numbered $1$ through $N$. We have $A_i$ pieces of Snack $i$.\nThere are $M$ children numbered $1$ through $M$. We will distribute the pieces of snacks to these children. Here, all of the following conditions must be satisfied.\n\n*   For every kind of snack, Child $i$ gets at most $B_i$ pieces of that kind.\n    \n*   Child $i$ gets at most $C_i$ pieces of snacks in total.\n    \n\nFind the maximum total number of pieces of snacks that can be distributed to the children under these conditions."},{"iden":"constraints","content":"*   $1 \\leq N \\leq 2 \\times 10^5$\n*   $1 \\leq M \\leq 2 \\times 10^5$\n*   $1 \\leq A_i \\leq 10^{12}$\n*   $1 \\leq B_i \\leq 10^7$\n*   $1 \\leq C_i \\leq 10^{12}$\n*   All values in input are integers."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$ $M$\n$A_1$ $A_2$ $\\cdots$ $A_N$\n$B_1$ $B_2$ $\\cdots$ $B_M$\n$C_1$ $C_2$ $\\cdots$ $C_M$"},{"iden":"sample input 1","content":"3 3\n2 5 5\n1 2 2\n5 3 5"},{"iden":"sample output 1","content":"11\n\nThe optimal distribution of snacks is as follows.\n\n*   Child $1$ gets $1$, $1$, $1$ piece of Snacks $1$, $2$, $3$, respectively.\n    \n*   Child $2$ gets $0$, $2$, $1$ piece(s) of Snacks $1$, $2$, $3$, respectively.\n    \n*   Child $3$ gets $1$, $2$, $2$ piece(s) of Snacks $1$, $2$, $3$, respectively."},{"iden":"sample input 2","content":"10 6\n3 54 62 64 25 89 1 47 77 4\n1 17 10 29 95 17\n32 40 90 27 50 9"},{"iden":"sample output 2","content":"211"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}