PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000193. Bắt tay tối ưu (Handshake)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Bắt tay tối ưu (Handshake)
Handshake
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are guests; guest has power . Takahashi performs exactly handshakes. In each handshake, he selects guest for his left hand and guest for his right hand, gaining happiness.
Choosing is allowed. No ordered pair may be used more than once. Therefore and count as distinct handshakes when .
Find the maximum total happiness obtainable with exactly handshakes.
Input
- First line: integers , .
- Second line: integers .
Output
- Print one integer: the maximum total happiness.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
5 3
10 14 19 34 33
Output
202
Explanation
For powers and , the three largest ordered-pair scores are:
| Handshake | Ordered pair | Score |
|---|---|---|
| 1 | ||
| 2 | ||
| 3 |
The maximum is .