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

#TP0000024. Điều chỉnh đề thi (Contest Proposal)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Điều chỉnh đề thi (Contest Proposal)

Contest Proposal

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A programming contest must contain exactly nn problems. The desired upper bound for the difficulty of problem ii is bib_i. The existing nn proposals have difficulties aia_i. Both arrays aa and bb are initially sorted in non-decreasing order.

The organizers may repeatedly choose a positive integer ww, insert a proposed problem of difficulty ww, sort all proposals, and delete one with the greatest difficulty. Exactly nn proposals remain after each operation. Find the minimum number of operations needed to achieve ai≤bia_i\le b_i at every position ii.

Input

  • The first line contains nn, the number of contest problems.
  • The second line contains nn integers a1,…,ana_1,\ldots,a_n in non-decreasing order.
  • The third line contains nn integers b1,…,bnb_1,\ldots,b_n in non-decreasing order, the desired upper bounds at each position.

Output

Print one integer: the minimum number of new proposals needed.

Subtasks

  • Subtask 1 (20 points): 1≤n≤51\le n\le 5; 1≤a1≤⋯≤an≤1091\le a_1\le\cdots\le a_n\le10^9; 1≤b1≤⋯≤bn≤1091\le b_1\le\cdots\le b_n\le10^9.
  • Subtask 2 (30 points): 1≤n≤301\le n\le 30; 1≤a1≤⋯≤an≤1091\le a_1\le\cdots\le a_n\le10^9; 1≤b1≤⋯≤bn≤1091\le b_1\le\cdots\le b_n\le10^9.
  • Subtask 3 (50 points): 1≤n≤1001\le n\le 100; 1≤a1≤⋯≤an≤1091\le a_1\le\cdots\le a_n\le10^9; 1≤b1≤⋯≤bn≤1091\le b_1\le\cdots\le b_n\le10^9.

Examples

Input

6
1000 1400 2000 2000 2200 2700
800 1200 1500 1800 2200 3000

Output

2

Explanation

Insert a problem of difficulty 800800 and delete the most difficult one, 27002700, obtaining [800,1000,1400,2000,2000,2200][800,1000,1400,2000,2000,2200]. Then insert 18001800 and remove 22002200, obtaining [800,1000,1400,1800,2000,2000][800,1000,1400,1800,2000,2000]. Every entry now satisfies its corresponding bound in bb. One operation cannot be sufficient because at least two proposals cannot be retained in a valid final array; hence the answer is 22.