#TP0000028. Mua sơn cho các phòng (Room Painting)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mua sơn cho các phòng (Room Painting)
Room Painting
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Joe is painting rooms using different paint colors. For color , he needs exactly microlitres of paint. The shop offers cans in fixed sizes , measured in microlitres.
Joe buys exactly one can for each color. The shop has an unlimited supply of every can size and can fill each with any color, so the same size may be selected for different colors. A chosen can must contain at least the required amount. It is guaranteed that some offered can size is large enough for every color. Find the minimum total paint wasted, in microlitres.
Input
- The first line contains , the numbers of offered can sizes and needed paint colors.
- Each of the next lines contains one integer , the size of a can offered by the shop, in microlitres.
- Each of the final lines contains one integer , the amount of paint needed for color , in microlitres.
Output
Print one integer: the minimum total number of wasted microlitres.
Subtasks
- Subtask 1 (20 points): ; for every element; .
- Subtask 2 (30 points): ; for every element; .
- Subtask 3 (50 points): ; for every element; .
Examples
Input
3 2
5
7
9
6
8
Output
2
Explanation
The first color needs microlitres, so the smallest suitable can has size , wasting . The second needs microlitres, so a size- can wastes . The minimum total waste is microlitres.