{"problem":{"name":"Ex - Bow Meow Optimization","description":{"content":"There are $N$ dogs numbered $1$ through $N$ and $M$ cats numbered $1$ through $M$. You will arrange the $(N+M)$ animals in a line from left to right. An arrangement causes each animal's **frustration*","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc290_h"},"statements":[{"statement_type":"Markdown","content":"There are $N$ dogs numbered $1$ through $N$ and $M$ cats numbered $1$ through $M$. You will arrange the $(N+M)$ animals in a line from left to right. An arrangement causes each animal's **frustration** as follows:\n\n*   The frustration of dog $i$ is $A_i\\times|x-y|$, where $x$ and $y$ are the numbers of cats to the left and right of that dog, respectively.\n*   The frustration of cat $i$ is $B_i\\times|x-y|$, where $x$ and $y$ are the numbers of dogs to the left and right of that cat, respectively.\n\nFind the minimum possible sum of the frustrations.\n\n## Constraints\n\n*   $1\\leq N,M \\leq 300$\n*   $1\\leq A_i,B_i \\leq 10^9$\n*   All values in the input are integers.\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":"abc290_h","tags":[],"sample_group":[["2 2\n1 3\n2 4","6\n\nConsider the following arrangement: dog $1$, cat $2$, dog $2$, cat $1$, from left to right. Then,\n\n*   dog $1$'s frustration is $1\\times|0-2|=2$;\n*   dog $2$'s frustration is $3\\times|1-1|=0$;\n*   cat $1$'s frustration is $2\\times|2-0|=4$; and\n*   cat $2$'s frustration is $4\\times|1-1|=0$,\n\nso the sum of the frustrations is $6$. Rearranging the animals does not make the sum less than $6$, so the answer is $6$."],["1 2\n100\n100 290","390"],["5 7\n522 575 426 445 772\n81 447 629 497 202 775 325","13354"]],"created_at":"2026-03-03 11:01:14"}}