Self Study

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

In the third semester of the first grade of JOI High School, NN courses are given for MM weeks from the first week to the MM-th week. The courses are numbered from 11 to NN. In each week, NN classes are given. The ii-th class in each week is a class for Course ii.

Bitaro is a student of the first grade. In each of the N×MN \times M classes, he takes one of the following actions.

  • Action 1: Bitaro attends the class. If he attends a class for Course ii (1iN1 ≤ i ≤ N), the comprehension level of Course ii will be increased by A_iA\_i.
  • Action 2: Bitaro does not attend the class. Instead, he chooses any one of the courses, and studies for the chosen course by himself. If he studies for Course ii (1iN1 ≤ i ≤ N) by himself for the duration of a class, the comprehension level of Course ii will be increased by B_iB\_i.

In the beginning, the comprehension level of every course is 00. Since Bitaro wants to practice competitive programming after school, he will not study outside the duration of the classes. When all the classes in the third semester finish, the final examination will be held.

Bitaro does not want to get a failing grade. Therefore, he wants to maximize the minimum comprehension level of the courses at the moment of the final examination.

Given the length of the semester, the number of the courses, and the incremental values of the comprehension levels, write a program which calculates the maximum possible value of the minimum comprehension level of the courses at the moment of the final examination.

입력

Read the following data from the standard input. Given values are all integers.

\begin{align\*} & N\\,M \\\ & A\_1 \\, A\_2 \\, \cdots \\, A\_N \\\ & B\_1 \\, B\_2 \\, \cdots \\, B\_N\end{align\*}

출력

Write one line to the standard output. The output should contain the maximum possible value of the minimum comprehension level of the courses at the moment of the final examination.

제한

  • 1N300,0001 ≤ N ≤ 300\\,000.
  • 1M1,000,000,0001 ≤ M ≤ 1\\,000\\,000\\,000.
  • 1A_i1,000,000,0001 ≤ A\_i ≤ 1\\,000\\,000\\,000 (1iN1 ≤ i ≤ N).
  • 1B_i1,000,000,0001 ≤ B\_i ≤ 1\\,000\\,000\\,000 (1iN1 ≤ i ≤ N).