#GD0000215. Tết âm lịch và gọi món (Lunar New Year and Food Ordering)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tết âm lịch và gọi món (Lunar New Year and Food Ordering)
Lunar New Year and Food Ordering
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
The restaurant offers kinds of dishes. Initially kind has portions available at price each. There are customers, served in order; customer orders portions of kind . Portions are served one at a time. If the requested kind remains in stock, use it; otherwise use the cheapest remaining kind, breaking equal-price ties by smaller kind index. Stock is reduced immediately. If the restaurant runs out before completing an order, the customer pays , even for portions already served; those served portions are still removed from stock. Otherwise the customer pays the total price of all portions served. Determine the price paid by each customer.
Input
- Line 1 contains : the number of dish kinds and customers.
- Line 2 contains exactly integers , the initial portions of each kind in index order.
- Line 3 contains exactly integers , the respective prices per portion.
- The next lines each contain : the one-based requested kind index and the number of portions in order .
Output
Print lines; line contains the total charge of customer , or if the order cannot be fully served.
Subtasks
- Subtask 1 (20 points): ; ; ; for all from to ; and for all from to .
- Subtask 2 (30 points): ; ; ; for all from to ; and for all from to .
- Subtask 3 (50 points): ; ; ; for all from to ; and for all from to .
Examples
Input
3 4
2 1 3
5 2 4
1 2
2 2
1 1
3 2
Output
10
6
4
0
Explanation
Customer 1 receives two portions of kind , paying . Customer 2 gets one portion of kind for and one of kind for , paying . Kind is sold out, so customer 3 gets a portion of kind for . Only one portion remains when customer 4 requests two, so this incomplete order costs .