PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000048. Điều chỉnh các phần quà (Gifts Fixing)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Điều chỉnh các phần quà (Gifts Fixing)
Gifts Fixing
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are gifts, gift containing candies and oranges. One move on a gift removes one candy, one orange, or one of each simultaneously. Make all gifts identical in both quantities with the fewest moves.
Input
Line 1: . Line 2: numbers . Line 3: numbers .
Output
Print the minimum number of moves.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
3
3 5 6
3 2 3
Output
6
Explanation
The best common quantities are 3 candies and 2 oranges. The gifts require , , and moves, totaling 6.