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

#TP0000036. Những người bạn và nhà hàng (Friends and the Restaurant)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Những người bạn và nhà hàng (Friends and the Restaurant)

Friends and the Restaurant

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn friends. Friend ii plans to spend xix_i units of money and has a budget of yiy_i. On each day, a group of at least two friends visits the restaurant; the sum of their budgets must cover the sum of their intended expenses. Each friend may visit at most once, and some may never visit. Find the maximum number of visiting days. Groups are not restricted to exactly two people.

Input

  • The first line contains nn, the number of friends.
  • The second line contains nn integers x1,…,xnx_1,\ldots,x_n, the planned expenses.
  • The third line contains nn integers y1,…,yny_1,\ldots,y_n, the budgets. Corresponding entries refer to the same friend.

Output

Print one integer: the maximum number of visiting days.

Subtasks

  • Subtask 1 (20 points): 2≤n≤82\le n\le8; 1≤xi,yi≤1091\le x_i,y_i\le10^9 for all 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 2≤n≤20002\le n\le2000; 1≤xi,yi≤1091\le x_i,y_i\le10^9 for all 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 2≤n≤1000002\le n\le100000; 1≤xi,yi≤1091\le x_i,y_i\le10^9 for all 1≤i≤n1\le i\le n.

Examples

Input

6
8 3 9 2 4 5
5 3 1 4 5 10

Output

2

Explanation

On day one, friends 11 and 66 spend 8+5=138+5=13 and have 5+10=155+10=15. On day two, friends 2,4,52,4,5 spend 3+2+4=93+2+4=9 and have 3+4+5=123+4+5=12. Friend 33 stays home. Two days are possible, whereas three valid disjoint groups are not.