#BS0000338. Sạc máy tính trong buổi thi (Stressful Training)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Sạc máy tính trong buổi thi (Stressful Training)
Stressful Training
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are laptops with initial charges and per-minute consumption . The contest lasts minutes. At the start of a minute, a charger with fixed nonnegative integer output may be connected to at most one laptop for that minute. Its charge changes by if connected and by otherwise. Charges have no upper limit. Every laptop must have nonnegative charge at the start of minutes 1 through k; charge after minute k is irrelevant. Find the smallest output, or -1 if no output works.
Input
First line: . Second line: integers . Third line: integers .
Output
Print the minimum output, or -1.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input 1
2 4
3 2
4 2
Output 1
5
Explanation
Charge laptops 1,2,1 in the first three minutes. Their starting charges are (3,2), (4,0), (0,3), (1,1). Power 4 fails because the first two charging choices are forced and laptop 1 then becomes negative.
Input 2
2 2
2 10
3 15
Output 2
-1
Explanation
Both laptops require charging during the first minute, but only one can be charged.