PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000031. Làm việc theo nhóm (Teamwork)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Làm việc theo nhóm (Teamwork)
Teamwork
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
There are cows in a fixed order, and cow has skill . A farmer wants to divide them into teams.
Each team is a consecutive segment containing at most cows. Every cow in a team receives the maximum skill of any member of that team. A team of size with maximum skill contributes points.
Partition all cows to maximize the total score.
Input
The first line contains and .
The next integers, possibly on multiple lines, describe the cows’ skills in order.
Output
Print the maximum total score after partitioning the cows into teams.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
7 3
1
15
7
9
2
5
10
Output
84
Explanation
Partition into , , and . Their sizes are , , and , all at most . Their contributions are , , and , for an optimal total of .