No.1251 Minimization Problem You Must Not Get Wrong
タグ : / 解いたユーザー数 196
作問者 : 👑
Kazun
/ テスター :
Problem Statement
Using integers $A_1,\dots,A_N$ and positive integers $B_1,\dots,B_N$, define a function $f$ whose domain is the real numbers as
$\quad \displaystyle f(X)=\sum_{i=1}^N B_i |X-A_i|$
. Find a real number $X$ that minimizes $f$ and the value of $f(X)$ at that point.
Here, a real number $Y$ that minimizes a function $g$ whose domain is the real numbers is one that satisfies $g(Y) \leq g(Z)$ for every real number $Z$. It can be shown that, under the constraints of this problem, at least one real number minimizing $f$ exists. Note that there may be two or more real numbers minimizing $f$; in that case, you may output any one of them.
It can also be shown that, under the constraints of this problem, the minimum value is an integer.
Note
Although the title says "must not get wrong", there is actually no penalty for submitting an incorrect answer.Constraints
- $1 \leq N \leq 2 \times 10^5$
- $-10^6 \leq A_i \leq 10^6$
- $1 \leq B_i \leq 10^6$
- All inputs are integers.
Input
The input is given from standard input in the following format.$N$ $A_1~A_2~\dots~A_N$ $B_1~B_2~\dots~B_N$
Output
Output $X$ that minimizes $f$ and the value of $f(X)$ at that point. Separate these two numbers with a space, and end the output with a newline.
Sample
Sample 1
Input
1 0 1
Output
0 0
The integer $X$ that minimizes $f(X):=|X|$ is $X=0$, and in this case $f(0)=0$.
Sample 2
Input
3 1 2 3 1 2 3
Output
2 4
When $X=2$, $f(2)=4$ is the minimum, but $X=3$ also gives $f(3)=4$.
Sample 3
Input
10 1 1 2 3 5 8 13 21 34 55 1 2 3 4 5 1 2 3 4 5
Output
7.5 462
The value of $X$ that minimizes $f$ does not have to be an integer.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。