#B3933. Salary Distribution Problem
Salary Distribution Problem
Salary Distribution Problem
After the contest, the organizers Juan and Xia received a total salary of ( m ) yuan. The contest featured ( n ) problems. For the ( i )-th problem, the creator is denoted by ( a_i ), where ( a_i = 1 ) indicates Juan and ( a_i = 2 ) indicates Xia. Each problem has an associated wage weight ( b_i ). The salary for each problem is allocated in proportion to its weight, i.e., problem ( i ) receives ( m \times \frac{b_i}{\sum_{j=1}^{n}b_j} ) yuan. According to the distribution rule, the entire salary from each problem goes to its creator. Your task is to calculate the total salary that Juan receives.
inputFormat
The first line contains two integers ( m ) and ( n ) ((1 \le m \le 10^9,\ 1 \le n \le 10^5)). The second line contains ( n ) integers: ( a_1, a_2, \dots, a_n ), where each ( a_i ) is either 1 or 2. The third line contains ( n ) integers: ( b_1, b_2, \dots, b_n ) ((1 \le b_i \le 10^5)).
outputFormat
Output a single integer representing the total salary Juan (( a_i = 1 )) receives.
sample
100 3
1 2 1
3 2 5
80