A12393 | Stressful Training
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Berland SU holds yet another training contest for its students today. $n$ students came, each of them brought his laptop. However, it turned out that everyone has forgot their chargers!
Let students be numbered from $1$ to $n$ . Laptop of the $i$ -th student has charge $a_i$ at the beginning of the contest and it uses $b_i$ of charge per minute (i.e. if the laptop has $c$ charge at the beginning of some minute, it becomes $c - b_i$ charge at the beginning of the next minute). The whole contest lasts for $k$ minutes.
Polycarp (the coach of Berland SU) decided to buy a single charger so that all the students would be able to successfully finish the contest. He buys the charger at the same moment the contest starts.
Polycarp can choose to buy the charger with any non-negative (zero or positive) integer power output. The power output is chosen before the purchase, it can't be changed afterwards. Let the chosen power output be $x$ . At the beginning of each minute (from the minute contest starts to the last minute of the contest) he can plug the charger into any of the student's laptops and use it for some integer number of minutes. If the laptop is using $b_i$ charge per minute then it will become $b_i - x$ per minute while the charger is plugged in. Negative power usage rate means that the laptop's charge is increasing. The charge of any laptop isn't limited, it can become infinitely large. The charger can be plugged in no more than one laptop at the same time.
The student successfully finishes the contest if the charge of his laptop never is below zero at the beginning of some minute (from the minute contest starts to the last minute of the contest, zero charge is allowed). The charge of the laptop of the minute the contest ends doesn't matter.
Help Polycarp to determine the minimal possible power output the charger should have so that all the students are able to successfully finish the contest. Also report if no such charger exists.
Let students be numbered from $1$ to $n$ . Laptop of the $i$ -th student has charge $a_i$ at the beginning of the contest and it uses $b_i$ of charge per minute (i.e. if the laptop has $c$ charge at the beginning of some minute, it becomes $c - b_i$ charge at the beginning of the next minute). The whole contest lasts for $k$ minutes.
Polycarp (the coach of Berland SU) decided to buy a single charger so that all the students would be able to successfully finish the contest. He buys the charger at the same moment the contest starts.
Polycarp can choose to buy the charger with any non-negative (zero or positive) integer power output. The power output is chosen before the purchase, it can't be changed afterwards. Let the chosen power output be $x$ . At the beginning of each minute (from the minute contest starts to the last minute of the contest) he can plug the charger into any of the student's laptops and use it for some integer number of minutes. If the laptop is using $b_i$ charge per minute then it will become $b_i - x$ per minute while the charger is plugged in. Negative power usage rate means that the laptop's charge is increasing. The charge of any laptop isn't limited, it can become infinitely large. The charger can be plugged in no more than one laptop at the same time.
The student successfully finishes the contest if the charge of his laptop never is below zero at the beginning of some minute (from the minute contest starts to the last minute of the contest, zero charge is allowed). The charge of the laptop of the minute the contest ends doesn't matter.
Help Polycarp to determine the minimal possible power output the charger should have so that all the students are able to successfully finish the contest. Also report if no such charger exists.
输入格式
The first line contains two integers $n$ and $k$ ( $1 \le n \le 2 \cdot 10^5$ , $1 \le k \le 2 \cdot 10^5$ ) — the number of students (and laptops, correspondigly) and the duration of the contest in minutes.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^{12}$ ) — the initial charge of each student's laptop.
The third line contains $n$ integers $b_1, b_2, \dots, b_n$ ( $1 \le b_i \le 10^7$ ) — the power usage of each student's laptop.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^{12}$ ) — the initial charge of each student's laptop.
The third line contains $n$ integers $b_1, b_2, \dots, b_n$ ( $1 \le b_i \le 10^7$ ) — the power usage of each student's laptop.
输出格式
Print a single non-negative integer — the minimal possible power output the charger should have so that all the students are able to successfully finish the contest.
If no such charger exists, print -1.
If no such charger exists, print -1.
输入输出样例
输入 #1
2 4 3 2 4 2
输出 #1
5
输入 #2
1 5 4 2
输出 #2
1
输入 #3
1 6 4 2
输出 #3
2
输入 #4
2 2 2 10 3 15
输出 #4
-1
Let's take a look at the state of laptops in the beginning of each minute on the first example with the charger of power $5$ :
1. charge: $[3, 2]$ , plug the charger into laptop 1;
2. charge: $[3 - 4 + 5, 2 - 2] = [4, 0]$ , plug the charger into laptop 2;
3. charge: $[4 - 4, 0 - 2 + 5] = [0, 3]$ , plug the charger into laptop 1;
4. charge: $[0 - 4 + 5, 3 - 2] = [1, 1]$ .
The contest ends after the fourth minute.
However, let's consider the charger of power $4$ :
1. charge: $[3, 2]$ , plug the charger into laptop 1;
2. charge: $[3 - 4 + 4, 2 - 2] = [3, 0]$ , plug the charger into laptop 2;
3. charge: $[3 - 4, 0 - 2 + 4] = [-1, 2]$ , the first laptop has negative charge, thus, the first student doesn't finish the contest.
In the fourth example no matter how powerful the charger is, one of the students won't finish the contest.
1. charge: $[3, 2]$ , plug the charger into laptop 1;
2. charge: $[3 - 4 + 5, 2 - 2] = [4, 0]$ , plug the charger into laptop 2;
3. charge: $[4 - 4, 0 - 2 + 5] = [0, 3]$ , plug the charger into laptop 1;
4. charge: $[0 - 4 + 5, 3 - 2] = [1, 1]$ .
The contest ends after the fourth minute.
However, let's consider the charger of power $4$ :
1. charge: $[3, 2]$ , plug the charger into laptop 1;
2. charge: $[3 - 4 + 4, 2 - 2] = [3, 0]$ , plug the charger into laptop 2;
3. charge: $[3 - 4, 0 - 2 + 4] = [-1, 2]$ , the first laptop has negative charge, thus, the first student doesn't finish the contest.
In the fourth example no matter how powerful the charger is, one of the students won't finish the contest.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted