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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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 friends. Friend plans to spend units of money and has a budget of . 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 , the number of friends.
- The second line contains integers , the planned expenses.
- The third line contains integers , the budgets. Corresponding entries refer to the same friend.
Output
Print one integer: the maximum number of visiting days.
Subtasks
- Subtask 1 (20 points): ; for all .
- Subtask 2 (30 points): ; for all .
- Subtask 3 (50 points): ; for all .
Examples
Input
6
8 3 9 2 4 5
5 3 1 4 5 10
Output
2
Explanation
On day one, friends and spend and have . On day two, friends spend and have . Friend stays home. Two days are possible, whereas three valid disjoint groups are not.