Self Study
Time limit1sMemory limit512 MB
Given N courses over M weeks, each class Bitaro either attends (gaining A_i in course i) or self-studies one course (gaining B_i); maximize the minimum final comprehension across all courses.
- Level
Hard8 of 10
- Topics
- Binary search, Greedy, Math, Implementation
- Solved
- No attempts yet
Problem
In the third semester of the first grade of JOI High School, courses are given over weeks, from the first week to the -th week. The courses are numbered from to . In each week, classes are given. The -th class in each week is a class for Course .
Bitaro is a student of the first grade. In each of the classes, he takes one of the following actions.
- Action 1: Bitaro attends the class. If he attends a class for Course (), the comprehension level of Course will be increased by .
- 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 () by himself for the duration of a class, the comprehension level of Course will be increased by .
In the beginning, the comprehension level of every course is . 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.
Input
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*}
Output
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.
Constraints
- .
- .
- ().
- ().