PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000029. Devu học bài (Devu, the Dumb Guy)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Devu học bài (Devu, the Dumb Guy)
Devu, the Dumb Guy
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are subjects with difficulties . The initial multiplier is ; after each learned subject it decreases by but never below . The cost of a subject is its difficulty times the current multiplier. Minimize total cost.
Input
The first line contains . The second line contains .
Output
Print the minimum total cost.
Constraints
- .
- for .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): Full constraints.
Examples
Input
3 3
1 3 2
Output
10
Explanation
The sample follows the ordering rule described in the Vietnamese explanation and produces the shown optimum.