#GD0000073. Một cách chia mảng khác (Yet Another Array Partitioning Task)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Một cách chia mảng khác (Yet Another Array Partitioning Task)
Yet Another Array Partitioning Task
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array and integers , define the beauty of a contiguous segment of length at least as the sum of its largest elements (including negative values when present). Partition the entire array into exactly contiguous segments of length at least , maximizing the total beauty. Print the optimum and the increasing endpoints of the first segments.
Input
The first line contains . The second contains .
Output
Print the maximum total beauty. The next line must contain integers defining the contiguous segments. Any optimal valid partition is accepted.
Subtasks
- Subtask 1 (20 points): ; ; , ; for every .
- Subtask 2 (30 points): ; ; , ; for every .
- Subtask 3 (50 points): ; ; , ; for every .
Examples
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
2 4
Explanation
Cut positions 2, 4 produce segments [5,2], [5,2], [4,1,1,3,2]. Their beauties are 7, 7, 7, totaling 21. This matches the sum of the largest elements and is optimal.