题目传送门
一道诈骗题。
首先把题目中给的式子变个形:
当满足 时,,因此把 换到 更大的位置答案一定更优,所以不管分成几段,每次选择子段中最大的数作为 就能取到贡献的最大值,且该值与 取值无关。因此最大总评价就是给定序列所有数之和,即 。
AC Code
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 1e5+5;
int n, k;
LL a[N], ans;
int main() {
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
ans += a[i];
}
printf("%lld\n", ans);
return 0;
}