PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000122. Chia dãy đã sắp xếp (Array Splitting)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chia dãy đã sắp xếp (Array Splitting)
Array Splitting
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given a nondecreasing array , split it into exactly nonempty contiguous subarrays. The cost of a subarray is its maximum minus its minimum. Minimize the total cost.
Input
The first line has . The next line has nondecreasing integers .
Output
Print the minimum total splitting cost.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
6 3
4 8 15 16 23 42
Output
12
Explanation
Split into , and with costs . These cuts remove the two largest adjacent gaps and .