PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000025. Bàn phím nhắn tin (Text Messaging Outrage)
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àn phím nhắn tin (Text Messaging Outrage)
Text Messaging Outrage
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A keypad has keys and each key can contain at most characters. Typing the -th character on a key requires presses. There are characters with frequencies . Assign them to keys to minimize the total number of presses.
Input
The first line contains . The second line contains frequencies . It is guaranteed that .
Output
Print the minimum total number of key presses.
Constraints
- .
- .
- for .
Subtasks
- Subtask 1 (20 points): , .
- Subtask 2 (30 points): , .
- Subtask 3 (50 points): Full constraints.
Examples
Input
3 2 5
8 2 5 2 4
Output
31
Explanation
The sample follows the ordering rule described in the Vietnamese explanation and produces the shown optimum.