QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100

#23988. Snacks Distribution

Statistics

Problem Statement

Aoi from JOI High School decided to distribute snacks to her friends.

Aoi has $N$ friends, numbered from $1$ to $N$.

Aoi has $X$ ice creams and $Y$ chocolates. Aoi decided to distribute $1$ snack—either an ice cream or a chocolate—to each of her $N$ friends. Here, it is guaranteed that the total number of ice creams and chocolates is at least $N$. Therefore, Aoi is able to distribute snacks to all of her friends.

Friend $i$ ($1 \le i \le N$) gains a happiness of $A_i$ if they receive an ice cream, and a happiness of $B_i$ if they receive a chocolate.

Print the maximum possible total happiness gained by all of Aoi's friends.

Constraints

  • $1 \le N \le 200\,000$.
  • $0 \le X \le N$.
  • $0 \le Y \le N$.
  • $N \le X + Y$.
  • $1 \le A_i \le 10^9$ ($1 \le i \le N$).
  • $1 \le B_i \le 10^9$ ($1 \le i \le N$).
  • All input values are integers.

Subtasks

  1. ($5$ points) $N = 1$.
  2. ($5$ points) $X = N$, $Y = 0$.
  3. ($5$ points) $X = N$, $Y = N$.
  4. ($25$ points) $X = N$, $Y = 1$.
  5. ($25$ points) $X + Y = N$.
  6. ($10$ points) $N \le 10$.
  7. ($25$ points) No additional constraints.

Input

The input is given in the following format:

N X Y
A_1 A_2 … A_N
B_1 B_2 … B_N

Output

Print the maximum possible total happiness gained by all of Aoi's friends.

Do not print anything other than the answer. (For example, do not print any text prompting for input.)

For the answer format, you may refer to the practice problems and their sample solutions.

Sample 1

Input

2 1 1
10 20
40 30

Output

60

There are the following $2$ ways for Aoi to distribute the snacks:

  • If she gives an ice cream to friend $1$ and a chocolate to friend $2$, the total happiness is $A_1 + B_2 = 10 + 30 = 40$.
  • If she gives a chocolate to friend $1$ and an ice cream to friend $2$, the total happiness is $B_1 + A_2 = 40 + 20 = 60$.

Among these $2$ ways, the total happiness is maximized in the latter case, where the total happiness is $60$. Therefore, print $60$.

This sample input satisfies the constraints of Subtasks $5, 6, 7$.

Sample 2

Input

2 2 2
10 20
40 30

Output

70

There are the following $4$ ways for Aoi to distribute the snacks:

  • If she gives ice creams to both friend $1$ and friend $2$, the total happiness is $A_1 + A_2 = 10 + 20 = 30$.
  • If she gives an ice cream to friend $1$ and a chocolate to friend $2$, the total happiness is $A_1 + B_2 = 10 + 30 = 40$.
  • If she gives a chocolate to friend $1$ and an ice cream to friend $2$, the total happiness is $B_1 + A_2 = 40 + 20 = 60$.
  • If she gives chocolates to both friend $1$ and friend $2$, the total happiness is $B_1 + B_2 = 40 + 30 = 70$.

Among these $4$ ways, the total happiness is maximized in the last case, where the total happiness is $70$. Therefore, print $70$.

This sample input satisfies the constraints of Subtasks $3, 6, 7$.

Sample 3

Input

1 1 0
1234
5678

Output

1234

In this sample input, Aoi has only $1$ friend.

This sample input satisfies the constraints of Subtasks $1, 2, 5, 6, 7$.

Sample 4

Input

10 10 1
314159265 358979323 846264338 327950288 419716939 937510582 97494459 230781640 628620899 862803482
534211706 798214808 651328230 664709384 460955058 223172535 940812848 111745028 410270193 852110555

Output

5867599604

Note that the output may not fit in a 32-bit integer type.

This sample input satisfies the constraints of Subtasks $4, 6, 7$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.