PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000040. Tối đa hóa giá bán (Price Maximization)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tối đa hóa giá bán (Price Maximization)
Price Maximization
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are goods, where is even, and good weighs . Partition all goods into exactly pairs. A package of total weight sells for . Find the maximum total revenue over all packages.
Input
- The first line contains integers : the number of goods and the price divisor.
- The second line contains integers , their weights.
Output
Print the maximum total revenue after pairing all goods.
Subtasks
- Subtask 1 (20 points): ; and even; ; for all .
- Subtask 2 (30 points): ; and even; ; for all .
- Subtask 3 (50 points): ; and even; ; for all .
Examples
Input
6 3
3 2 7 1 4 8
Output
8
Explanation
Pair , , and . Their prices are , , and . The total is , which reaches the upper bound .