#P7337. Calculate Total Bottles of Happy Water

    ID: 20535 Type: Default 1000ms 256MiB

Calculate Total Bottles of Happy Water

Calculate Total Bottles of Happy Water

There are \( n \) people from VG's school heading to the NOIP exam. Each person has a transportation mode \( t_i \) and a "despondency" value \( q_i \). When a person goes to the exam, they buy one bottle of "happy water". However, if a person takes the school bus (i.e. \( t_i = 1 \)) and is willing to beat the wolf (i.e. \( q_i = 1 \)), they are part of a special group. Let \( k \) be the number of people in this group. If \( k \geq m \), then these \( k \) persons collectively need to buy only \( m \) bottles instead of \( k \) bottles.

The task is to calculate the total number of bottles purchased by all \( n \) people. Formally, let \( k = \#\{ i \mid t_i = 1 \text{ and } q_i = 1 \}\). Then the total number of bottles is given by:

[ \text{Total Bottles} = n - k + \min(k, m) ]

inputFormat

The first line contains two integers \( n \) and \( m \) \((1 \leq n \leq 10^5, 0 \leq m \leq n)\).

The second line contains \( n \) integers \( t_1, t_2, \dots, t_n \), where \( t_i \) is either 0 or 1.

The third line contains \( n \) integers \( q_1, q_2, \dots, q_n \), where \( q_i \) is either 0 or 1.

outputFormat

Output a single integer: the total number of bottles purchased by all \( n \) people.

sample

5 2
1 0 1 1 0
1 1 0 1 1
5