QOJ.ac

QOJ

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

#2628. 自学

統計

在 JOI 高中一年级的第三学期,学校开设了 $N$ 门课程,持续时间为从第 1 周到第 $M$ 周,共 $M$ 周。课程编号为 1 到 $N$。每周都会开设 $N$ 节课,其中每周的第 $i$ 节课是课程 $i$ 的课。

Bitaro 是一名一年级学生。在总共 $N \times M$ 节课中,他可以采取以下两种行动之一:

  • 行动 1:Bitaro 去上课。如果他参加了课程 $i$ ($1 \le i \le N$) 的课,课程 $i$ 的理解程度将增加 $A_i$。
  • 行动 2:Bitaro 不去上课。相反,他选择任意一门课程,并进行自学。如果他自学课程 $i$ ($1 \le i \le N$) 的时长相当于一节课,课程 $i$ 的理解程度将增加 $B_i$。

起初,每门课程的理解程度均为 0。由于 Bitaro 放学后想练习竞技编程,他不会在课外时间进行学习。当第三学期的所有课程结束后,将进行期末考试。

Bitaro 不想挂科。因此,他希望最大化期末考试时所有课程中理解程度的最小值。

给定学期长度、课程数量以及各课程理解程度的增量,编写一个程序,计算期末考试时各课程理解程度的最小值的最大可能值。

输入格式

从标准输入读取以下数据。给定值均为整数。

$N \ M$ $A_1 \ A_2 \ \dots \ A_N$ $B_1 \ B_2 \ \dots \ B_N$

输出格式

输出一行到标准输出。该输出应包含期末考试时各课程理解程度的最小值的最大可能值。

数据范围

  • $1 \le N \le 300\,000$
  • $1 \le M \le 1\,000\,000\,000$
  • $1 \le A_i \le 1\,000\,000\,000$ ($1 \le i \le N$)
  • $1 \le B_i \le 1\,000\,000\,000$ ($1 \le i \le N$)

子任务

  1. (10 分) $M = 1$。
  2. (25 分) $N \times M \le 300\,000$,$A_i = B_i$ ($1 \le i \le N$)。
  3. (27 分) $N \times M \le 300\,000$。
  4. (29 分) $A_i = B_i$ ($1 \le i \le N$)。
  5. (9 分) 无附加限制。

样例

样例输入 1

3 3
19 4 5
2 6 2

样例输出 1

18

说明

例如,如果 Bitaro 按以下方式学习,课程 1、2、3 的理解程度将分别为 19、18、19。

  • 第一周,在课程 1 的时间,他自学课程 2。
  • 第一周,在课程 2 的时间,他自学课程 2。
  • 第一周,在课程 3 的时间,他参加课程 3 的课。
  • 第二周,在课程 1 的时间,他参加课程 1 的课。
  • 第二周,在课程 2 的时间,他自学课程 3。
  • 第二周,在课程 3 的时间,他参加课程 3 的课。
  • 第三周,在课程 1 的时间,他自学课程 3。
  • 第三周,在课程 2 的时间,他自学课程 2。
  • 第三周,在课程 3 的时间,他参加课程 3 的课。

由于课程理解程度的最小值不可能大于或等于 19,因此输出 18。

样例输入 2

2 1
9 7
2 6

样例输出 2

7

样例输入 3

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

样例输出 3

41397427274960

样例输入 4

4 25
1 2 3 4
1 2 3 4

样例输出 4

48

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.