#P8161. [JOI 2022 Final] 自学 / Self Study

[JOI 2022 Final] 自学 / Self Study

Problem Description

During the third term of the first year at JOI High School, which lasts for MM weeks, there are NN subjects numbered 1N1 \sim N. Each week has NN class periods. In period ii, there is a class of subject ii.

Bitaro is a first-year high school student. For each of the N×MN \times M class periods, he will choose one of the following actions:

  • Action 1: Bitaro attends the class. If he attends one class of subject ii, then his level of understanding of subject ii increases by AiA_i.
  • Action 2: Bitaro does not attend the class. Instead, he chooses any subject and does self-study for that subject. If he chooses subject ii and self-studies for one class period, then his level of understanding of subject ii increases by BiB_i.

At the beginning, his level of understanding for every subject is 00. Since Bitaro wants to practice programming contests after school, he will not study outside of class periods. After all class periods in the third term end, the final exams will be held.

Bitaro does not want to fail. Therefore, he wants to maximize the minimum value of his level of understanding among all subjects at the time of the final exams.

Given the term length, the number of subjects, and the increase values of understanding, write a program to compute the maximum possible value of the minimum level of understanding among all subjects at the time of the final exams.

Input Format

The first line contains two positive integers N,MN, M.

The second line contains NN positive integers A1,A2,,ANA_1, A_2, \ldots, A_N.

The third line contains NN positive integers B1,B2,,BNB_1, B_2, \ldots, B_N.

Output Format

Output one line containing one number, which is the maximum possible value of the minimum level of understanding among all subjects at the time of the final exams.

3 3
19 4 5
2 6 2

18

2 1
9 7
2 6

7

5 60000
630510219 369411957 874325200 990002527 567203997
438920902 634940661 593780254 315929832 420627496

41397427274960

4 25
1 2 3 4
1 2 3 4

48

Hint

[Sample Explanation #1]

For example, if Bitaro studies in the following way, then his levels of understanding of subjects 1,2,31, 2, 3 will be 19,18,1919, 18, 19, respectively.

  • Week 1, subject 11 period: self-study subject 22.
  • Week 1, subject 22 period: self-study subject 22.
  • Week 1, subject 33 period: attend the class of subject 33.
  • Week 2, subject 11 period: attend the class of subject 11.
  • Week 2, subject 22 period: self-study subject 33.
  • Week 2, subject 33 period: attend the class of subject 33.
  • Week 3, subject 11 period: self-study subject 33.
  • Week 3, subject 22 period: self-study subject 22.
  • Week 3, subject 33 period: attend the class of subject 33.

Since the minimum level of understanding among all subjects cannot be greater than or equal to 1919, output 1818.

This sample satisfies the constraints of subtasks 3,53, 5.

[Sample Explanation #2]

This sample satisfies the constraints of subtasks 1,3,51, 3, 5.

[Sample Explanation #3]

This sample satisfies the constraints of subtasks 3,53, 5.

[Sample Explanation #4]

This sample satisfies the constraints of subtasks 2,3,4,52, 3, 4, 5.


[Constraints]

This problem uses bundled testdata.

For all testdata (100%100\%), 1N3×1051 \le N \le 3 \times {10}^5, 1M1091 \le M \le {10}^9, 1Ai,Bi1091 \le A_i, B_i \le {10}^9.

  • Subtask 11 (1010 points): M=1M = 1.
  • Subtask 22 (2525 points): NM3×105N \cdot M \le 3 \times {10}^5, Ai=BiA_i = B_i.
  • Subtask 33 (2727 points): NM3×105N \cdot M \le 3 \times {10}^5.
  • Subtask 44 (2929 points): Ai=BiA_i = B_i.
  • Subtask 55 (99 points): no additional constraints.

Translated from JOI 2022 Final T2 “自習 / Self Study”.

Translated by ChatGPT 5