{"problem":{"name":"J. Restorer Distance","description":{"content":"You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_i$, the height is measured in number of bricks. After the restoration","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10259J"},"statements":[{"statement_type":"Markdown","content":"You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_i$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights.\n\nYou are allowed the following operations:\n\nYou cannot create additional pillars or ignore some of pre-existing pillars even if their height becomes $0$.\n\nWhat is the minimal total cost of restoration, in other words, what is the minimal total cost to make all the pillars of equal height?\n\nThe first line of input contains four integers $N$, $A$, $R$, $M$ ($1 <= N <= 10^5$, $0 <= A, R, M <= 10^4$) — the number of pillars and the costs of operations.\n\nThe second line contains $N$ integers $h_i$ ($0 <= h_i <= 10^9$) — initial heights of pillars.\n\nPrint one integer — the minimal cost of restoration.\n\n## Input\n\nThe first line of input contains four integers $N$, $A$, $R$, $M$ ($1 <= N <= 10^5$, $0 <= A, R, M <= 10^4$) — the number of pillars and the costs of operations.The second line contains $N$ integers $h_i$ ($0 <= h_i <= 10^9$) — initial heights of pillars.\n\n## Output\n\nPrint one integer — the minimal cost of restoration.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ N \\in \\mathbb{Z}^+ $ be the number of pillars.  \nLet $ A, R, M \\in \\mathbb{R}_{\\geq 0} $ be the costs per brick for adding, removing, and moving a brick, respectively.  \nLet $ H = (h_1, h_2, \\dots, h_N) $ be the initial height vector of the pillars, where $ h_i \\in \\mathbb{Z}_{\\geq 0} $.  \nLet $ x \\in \\mathbb{Z}_{\\geq 0} $ be the target uniform height of all pillars after restoration.\n\n**Constraints**  \n1. $ 1 \\leq N \\leq 10^5 $  \n2. $ 0 \\leq A, R, M \\leq 10^4 $  \n3. $ 0 \\leq h_i \\leq 10^9 $ for all $ i \\in \\{1, \\dots, N\\} $\n\n**Objective**  \nMinimize the total cost:  \n$$\n\\min_{x \\in \\mathbb{Z}_{\\geq 0}} \\left( A \\cdot \\sum_{i=1}^N \\max(0, x - h_i) + R \\cdot \\sum_{i=1}^N \\max(0, h_i - x) + M \\cdot \\min\\left( \\sum_{i=1}^N \\max(0, x - h_i), \\sum_{i=1}^N \\max(0, h_i - x) \\right) \\right)\n$$","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10259J","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}