PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000113. Giao dịch thẻ bài (Card Trading)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Giao dịch thẻ bài (Card Trading)
Card Trading
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
You own trading cards of types, indexed from to . To form a collection, retain exactly two cards of each of exactly chosen types; sell all other cards and buy missing cards as needed. A card of type costs to buy and sells for . Maximize net earnings after assembling the collection.
Input
Line 1 contains . Line 2 contains the types of the owned cards. The next lines contain for type .
Output
Print the maximum net earnings, possibly negative.
Subtasks
- Subtask 1 (20 points): ; ; all lá thuộc loại ; .
- Subtask 2 (30 points): ; ; all lá thuộc loại ; .
- Subtask 3 (50 points): ; ; all lá thuộc loại ; .
Examples
Input
4 3 1
1 1 2 3
5 2
6 3
4 1
Output
4
Explanation
Selling everything earns . Keeping a pair of type costs in forgone sale revenue, yielding . Completing type costs and type costs , so type is best.