#TP0000022. Mua hộp kẹo lưu niệm (Souvenirs)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mua hộp kẹo lưu niệm (Souvenirs)
Souvenirs
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
A souvenir shop sells boxes of candy. Box costs yen and contains exactly pieces of candy. Takahashi wants to buy boxes and give one to each of people.
Person must receive a box containing at least pieces. Each box may be purchased and assigned only once. Determine the minimum total cost of satisfying everybody. If it is impossible, print -1.
Input
- The first line contains , the number of available boxes and recipients, with .
- The second line contains integers , both the price and the candy count of each box.
- The third line contains integers , each person's minimum candy requirement.
Output
Print one integer: the minimum total price, or -1 if no valid assignment exists.
Subtasks
- Subtask 1 (20 points): ; for every element.
- Subtask 2 (30 points): ; for every element.
- Subtask 3 (50 points): ; for every element.
Examples
Input
4 2
3 4 5 4
1 4
Output
7
Explanation
The person requiring at least candy can receive the box costing , which contains candies. The person requiring at least candies can receive either box costing . The total cost is . There is no cheaper box satisfying the second person, so the minimum is .