PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000117. Thay đổi giá trị trên thẻ (Integer Cards)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Thay đổi giá trị trên thẻ (Integer Cards)
Integer Cards
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are cards with initial values . For each of operations in order, you may choose at most cards and overwrite their values with . Cards may be rewritten multiple times. Maximize the final sum.
Input
The first line has , the second has values , followed by lines with .
Output
Print the maximum final sum of all cards.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
3 2
1 2 3
1 5
2 4
Output
13
Explanation
Replace the card worth with , and the cards worth and with . The resulting values sum to .