QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 512 MB 満点: 100

#3263. Final Exam

統計

There are $n$ students, each of whom has taken final exams for all $m$ courses and is anxiously waiting for the results to be released.

The $i$-th student hopes to receive the results for all $m$ courses on or before day $t_i$. If, on day $t_i$, at least one course's result has not been released, the student will wait until the last course's result is released, incurring an unhappiness value of $C$ for each day they wait.

For the $i$-th course, according to the original plan, the result will be released on day $b_i$.

There are two types of operations to adjust the release dates: 1. Reassign some teachers responsible for course $X$ to course $Y$. This delays the release of course $X$ by one day and advances the release of course $Y$ by one day. Each operation incurs an unhappiness value of $A$. 2. Assign additional teachers to be responsible for subject $Z$. This advances the release of subject $Z$ by one day. Each operation incurs an unhappiness value of $B$.

The parameters $X, Y, Z$ in the above operations can be specified arbitrarily. Each operation can be performed multiple times, and the parameters can be re-specified each time.

You are asked to perform operations reasonably to minimize the total unhappiness value. Output the minimum total unhappiness value.

Input

The first line contains three non-negative integers $A, B, C$, describing the three types of unhappiness values, as detailed in the description.

The second line contains two positive integers $n, m$ ($1 \le n, m \le 10^5$), representing the number of students and the number of courses, respectively.

The third line contains $n$ positive integers $t_i$, representing the day each student hopes to receive their results.

The fourth line contains $m$ positive integers $b_i$, representing the day each course's result is scheduled to be released according to the original plan.

Output

Output a single integer representing the minimum total unhappiness value.

Examples

Input 1

100 100 2
4 5
5 1 2 3
1 1 2 3 3

Output 1

6

Note 1

Since the unhappiness caused by adjustment operations is too high, the best strategy in this case is to make no adjustments. Among all 5 courses, the latest result is released on day 3.

  • Student 1 hopes to receive results on or before day 5, so no unhappiness is incurred.
  • Student 2 hopes to receive results on or before day 1, incurring an unhappiness of $(3 - 1) \times 2 = 4$.
  • Student 3 hopes to receive results on or before day 2, incurring an unhappiness of $(3 - 2) \times 2 = 2$.
  • Student 4 hopes to receive results on or before day 3, so no unhappiness is incurred.

The total unhappiness is $4 + 2 = 6$.

Input 2

3 5 4
5 6
1 1 4 7 8
2 3 3 1 8 2

Output 2

33

Input 3

See exam/exam3.in and exam/exam3.ans in the contestant directory.

Constraints

Test Cases $n, m, t_i, b_i$ $A, B, C$
1, 2 $1 \le n, m, t_i, b_i \le 2,000$ $A = 10^9; B = 10^9; 0 \le C \le 10^2$
3, 4 $0 \le A, C \le 10^2; B = 10^9$
5, 6, 7, 8 $0 \le B \le A \le 10^2; 0 \le C \le 10^2$
9, 10, 11, 12 $0 \le A, B, C \le 10^2$
13, 14 $1 \le n, m, t_i, b_i \le 10^5$ $0 \le A, B \le 10^5; C = 10^{16}$
15, 16, 17, 18, 19, 20 $0 \le A, B, C \le 10^5$

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.