Random Variables · Conditional Expectation (Optional)
Lesson 6
Programming problem. The same question can be asked for absolute error with weights. The loss is now \[\sum_{i=1}^{n}w_{i}|y_{i}-c|, \qquad w_{i} \ge 0.\]
The first line of the input contains an integer \(n\). The second line contains \(n\) integers \(y_{1},\dotsc,y_{n}\). The third line contains \(n\) integers \(w_{1},\dotsc,w_{n}\). You may assume that \(1 \le n \le 10^{5}\), \(|y_{i}| \le 10^{9}\), and \(0 \le w_{i} \le 10^{9}\).
Output one real number: any value of \(c\) that minimizes the weighted absolute error. If all weights are zero, every value of \(c\) is optimal. If several values are optimal, output any one of them.
Public samples
Input
1 7 1
Expected output
7