D. Array Splitting(后缀数组)
Posted cherish-lin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了D. Array Splitting(后缀数组)相关的知识,希望对你有一定的参考价值。
You are given an array ??1,??2,…,???? and an integer ??
.
You are asked to divide this array into ??
non-empty consecutive subarrays. Every element in the array should be included in exactly one subarray. Let ?? be the index of subarray the ??-th element belongs to. Subarrays are numbered from left to right and from 1 to ??
.
Let the cost of division be equal to ∑??=1??(????⋅??
. For example, if ??=[1,−2,−3,4,−5,6,−7] and we divide it into 3 subbarays in the following way: [1,−2,−3],[4,−5],[6,−7], then the cost of division is equal to 1⋅1−2⋅1−3⋅1+4⋅2−5⋅2+6⋅3−7⋅3=−9
.
Calculate the maximum cost you can obtain by dividing the array ??
into ??
non-empty consecutive subarrays.
The first line contains two integers ??
and ?? (1≤??≤??≤3⋅105
).
The second line contains ??
integers ??1,??2,…,???? (|????|≤106
).
Print the maximum cost you can obtain by dividing the array ??
into ??
以上是关于D. Array Splitting(后缀数组)的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #246 (Div. 2) D. Prefixes and Suffixe 后缀数组
Codeforces Round #244 (Div. 2) D. Match & Catch 后缀数组