PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000338. Sạc máy tính trong buổi thi (Stressful Training)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 nn laptops with initial charges aia_i and per-minute consumption bib_i. The contest lasts kk minutes. At the start of a minute, a charger with fixed nonnegative integer output xx may be connected to at most one laptop for that minute. Its charge changes by x−bix-b_i if connected and by −bi-b_i 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: n,kn,k. Second line: nn integers aia_i. Third line: nn integers bib_i.

Output

Print the minimum output, or -1.

Subtasks

  • Subtask 1 (20 points): 1≤n≤41\le n\le4; 1≤k≤61\le k\le6; 1≤ai≤121\le a_i\le12; 1≤bi≤41\le b_i\le4.
  • Subtask 2 (30 points): 1≤n,k≤2⋅1051\le n,k\le2\cdot10^5; 1≤ai≤10121\le a_i\le10^{12}; 1≤bi≤1071\le b_i\le10^7; b1=⋯=bnb_1=\cdots=b_n.
  • Subtask 3 (50 points): 1≤n,k≤2⋅1051\le n,k\le2\cdot10^5; 1≤ai≤10121\le a_i\le10^{12}; 1≤bi≤1071\le b_i\le10^7.

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.