#P7337. 『MdOI R4』Fun

    ID: 7775 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 1 上传者: 标签>模拟O2优化基础算法枚举洛谷月赛

『MdOI R4』Fun

Background

When going to the NOIP exam site, there are two fine traditions: “fighting wolves” and drinking “happy water”. Both activities can bring students happiness.

Problem Description

There are nn people in VG’s school who are going to take NOIP.

Each person has a way of transportation. For person ii, the transportation is tit_i. If ti=1t_i=1, this person takes the school bus; if ti=0t_i=0, this person goes to the exam site by themselves.

Each person has a “depressed value”. For person ii, the depressed value is qiq_i. If qi=1q_i=1, this person is willing to “fight wolves”; if qi=0q_i=0, this person is not willing to “fight wolves”.

Everyone will buy one bottle of “happy water” when going to the exam site. However, if the number of people who both take the bus and are willing to “fight wolves” (i.e., the count of ii satisfying ti=1t_i=1 and qi=1q_i=1) is kk, and kk is not less than mm, then these kk people only need to buy mm bottles of “happy water” in total.

Now VG has collected everyone’s transportation and “depressed value”. Please help him compute the final total number of bottles of “happy water” bought by everyone.

Input Format

The first line contains three integers n,m,typen,m,type. Here typetype is the special constraint ID; see Constraints for its meaning. It may help you get partial scores, but the correct solution does not rely on it.

The second line contains nn integers, where the ii-th integer is tit_i.

The third line contains nn integers, where the ii-th integer is qiq_i.

Output Format

Output one integer in one line, the final total number of bottles of “happy water” bought by everyone.

3 1 3
1 0 1
0 1 1

3

3 1 3
1 1 1
0 1 1

2

Hint

[Sample Explanation #1]

The situations of the three people are as follows:

  • Person 11 takes the bus but does not “fight wolves”;

  • Person 22 “fights wolves” but does not take the bus;

  • Person 33 takes the bus and also “fights wolves”.

So, only 11 person both takes the bus and “fights wolves”, which satisfies the condition of being not less than mm. Therefore, these 11 person need to buy mm bottles of “happy water”, and the remaining 22 people buy 22 bottles of “happy water”. In total, 33 bottles of “happy water” are needed.

[Constraints]

This problem does not use bundled testcases.

Test Point ID n,mn,m typetype tit_i qiq_i
11 30\le 30 =0=0
22 70\le 70
33 30\le 30 =1=1
44 70\le 70
55 n=mn=m =2=2 No special constraints
66
77
88 No special constraints =3=3
99
1010

For 100%100\% of the data, 1mn1001 \le m \le n \le 100, ti,qi{0,1}t_i,q_i \in \{0,1\}, type{0,1,2,3}type \in \{0,1,2,3\}.

Translated by ChatGPT 5