{"problem":{"name":"Not Too Many Balls","description":{"content":"There are several balls. Each ball is one of the colors $1$, $2$, $\\ldots$, $N$, and for each $i = 1, 2, \\ldots, N$, there are $A_i$ balls of color $i$. Additionally, there are $M$ boxes. For each $j ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":3000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc332_g"},"statements":[{"statement_type":"Markdown","content":"There are several balls. Each ball is one of the colors $1$, $2$, $\\ldots$, $N$, and for each $i = 1, 2, \\ldots, N$, there are $A_i$ balls of color $i$.\nAdditionally, there are $M$ boxes. For each $j = 1, 2, \\ldots, M$, the $j$\\-th box can hold up to $B_j$ balls in total.\nHere, for all pairs of integers $(i, j)$ satisfying $1 \\leq i \\leq N$ and $1 \\leq j \\leq M$, the $j$\\-th box may hold at most $(i \\times j)$ balls of color $i$.\nPrint the maximum total number of balls that the $M$ boxes can hold.\n\n## Constraints\n\n*   All input values are integers.\n*   $1 \\leq N \\leq 500$\n*   $1 \\leq M \\leq 5 \\times 10^5$\n*   $0 \\leq A_i, B_i \\leq 10^{12}$\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$ $M$\n$A_1$ $A_2$ $\\ldots$ $A_N$\n$B_1$ $B_2$ $\\ldots$ $B_M$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc332_g","tags":[],"sample_group":[["2 3\n8 10\n4 3 8","14\n\nYou can do as follows to put a total of $14$ balls into the boxes while satisfying the conditions in the problem statement.\n\n*   For balls of color $1$, put one into the first box, one into the second box, and three into the third box.\n*   For balls of color $2$, put two into the first box, two into the second box, and five into the third box."],["1 1\n1000000000000\n0","0"],["10 12\n59 168 130 414 187 236 330 422 31 407\n495 218 351 105 351 414 198 230 345 297 489 212","2270"]],"created_at":"2026-03-03 11:01:13"}}