#B3938. Protecting the Barns
Protecting the Barns
Protecting the Barns
bj12z_jiasiyuan owns a farm with \(n\) barns numbered from \(1\) to \(n\). The \(i\)th barn has an initial defense value of \(a_i\). A meteor shower will occur in \(t\) seconds, during which \(m\) meteorites will hit the barns. The \(i\)th meteorite will strike barn number \(x_i\), reducing its defense value by \(2\) points per hit. A barn is destroyed if its defense value becomes \(\leq 0\) after the meteor strikes.
Fortunately, bj12z_jiasiyuan possesses an unlimited supply of defense boosts. Each boost increases a barn's defense by \(1\) point. Moreover, the hero Qianlunzong (卷王) can teleport instantly between barns so that travel time is not an issue. However, every boost takes \(1\) second to deploy, and Qianlunzong only has \(t\) seconds to use the boosts before the meteor shower strikes.
For each barn \(i\), let \(h_i\) be the number of meteorites that hit it. Its defense after the meteor shower will be:
[ a_i + s_i - 2,h_i, ]
where \(s_i\) is the number of boosts given to barn \(i\). To keep barn \(i\) from being destroyed, it must satisfy:
[ a_i + s_i - 2,h_i > 0. ]
Thus, the minimum boosts required for barn \(i\) is:
[ \max\Big(0, 2,h_i - a_i + 1\Big). ]
</p>Your task is to determine the maximum number of barns that can be saved if Qianlunzong deploys the boosts optimally within \(t\) seconds.
inputFormat
The input consists of three lines:
- The first line contains three integers \(n\), \(t\), and \(m\) \( (1 \leq n, t, m \leq 10^5)\), representing the number of barns, the number of seconds available for boosts, and the number of meteorites, respectively.
- The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\) \( (1 \leq a_i \leq 10^9)\), the initial defense values of each barn.
- The third line contains \(m\) integers \(x_1, x_2, \ldots, x_m\) \( (1 \leq x_i \leq n)\), where each \(x_i\) indicates that the \(i\)th meteorite will hit barn \(x_i\).
outputFormat
Output a single integer: the maximum number of barns that can be saved from destruction under an optimal deployment of boosts.
sample
3 3 3
2 2 2
1 2 3
3
</p>