#P9519. Happiness Distribution
Happiness Distribution
Happiness Distribution
Today is payday at company L. There are \(n\) employees standing in a line, numbered from \(1\) to \(n\). The \(i\)th employee has an expected happiness value \(a_i\).
The boss, being very tightfisted, selects only \(m\) employees with indices \(b_1, b_2, \dots, b_m\) to receive a wage of \(k\) units each. However, the employees are very empathetic: not only does an employee increase his/her own happiness when receiving the wage, but he/she also gains extra happiness when nearby colleagues receive the wage.
More precisely, when an employee at position \(A\) (with index \(i\)) receives the wage, for any employee (including A) at a distance \(d = |i - j|\), the employee at position \(j\) increases his/her happiness by \(\max(0, k-d)\). In particular, if employee A receives the wage then A’s own happiness increases by \(k\) (since \(d=0\)).
The boss wants you to determine the minimum integer \(k\) such that, after the wages are given, every employee's total happiness is at least his/her expected happiness \(a_i\> for every \(1 \leq i \leq n\).
The contribution to an employee's happiness is the sum of the contributions from each wage receiver. Formally, for a given \(k\), the total happiness of employee \(i\) is
\[
H_i = \sum_{j=1}^{m} \max(0, k - |i - b_j|).
\]
You are to find the minimum \(k\) such that \(H_i \ge a_i\) for all \(1 \le i \le n\>.
inputFormat
The first line contains two integers \(n\) and \(m\) \((1 \leq n, m \leq 10^5)\), representing the total number of employees and the number of wage receivers, respectively.
The second line contains \(n\) integers \(a_1, a_2, \dots, a_n\) \((0 \leq a_i \leq 10^9)\), where \(a_i\) is the expected happiness value of the \(i\)th employee.
The third line contains \(m\) distinct integers \(b_1, b_2, \dots, b_m\) \((1 \leq b_i \leq n)\), the indices of the employees who receive the wage.
outputFormat
Output a single integer, the minimum \(k\) that satisfies the condition that every employee's total happiness is at least his/her expected happiness.
sample
5 2
3 3 3 3 3
2 4
4