Random Variables · Conditional Expectation (Optional)

Lesson 4

Nikolai Chukhin · Alexander S. Kulikov

Programming problem. In many datasets, not all observations should count equally. Some measurements may be more reliable, some users may represent larger groups, and some examples may be deliberately emphasized during training. This leads to the weighted squared loss \[\sum_{i=1}^{n}w_{i}(y_{i}-c)^{2}, \qquad w_{i} \ge 0.\] The programming task below asks for the best constant predictor for this loss.

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 squared loss. If all weights are zero, every value of \(c\) is optimal. Your answer will be accepted if its absolute error is at most \(10^{-9}\) or its relative error is at most \(10^{-6}\).

1 point
Public samples
Public sample 1
Input
1
7
1
Expected output
7