CF1197D.Yet Another Subarray Problem
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a1,a2,…,an and two integers m and k.
You can choose some subarray al,al+1,…,ar−1,ar.
The cost of subarray al,al+1,…,ar−1,ar is equal to i=l∑rai−k⌈mr−l+1⌉, where ⌈x⌉ is the least integer greater than or equal to x.
The cost of empty subarray is equal to zero.
For example, if m=3, k=10 and a=[2,−4,15,−3,4,8,3], then the cost of some subarrays are:
- a3…a3:15−k⌈31⌉=15−10=5;
- a3…a4:(15−3)−k⌈32⌉=12−10=2;
- a3…a5:(15−3+4)−k⌈33⌉=16−10=6;
- a3…a6:(15−3+4+8)−k⌈34⌉=24−20=4;
- a3…a7:(15−3+4+8+3)−k⌈35⌉=27−20=7.
Your task is to find the maximum cost of some subarray (possibly empty) of array a.
给你一个数组 a1,a2,…,an 和两个整数 m 和 k。
你可以选择某个子数组 al,al+1,…,ar−1,ar。
子数组 al,al+1,…,ar−1,ar 的代价定义为 i=l∑rai−k⌈mr−l+1⌉,其中 ⌈x⌉ 表示不小于 x 的最小整数。
空子数组的代价为 0。
例如,若 m=3,k=10,且 a=[2,−4,15,−3,4,8,3],则某些子数组的代价如下:
- a3…a3:15−k⌈31⌉=15−10=5;
- a3…a4:(15−3)−k⌈32⌉=12−10=2;
- a3…a5:(15−3+4)−k⌈33⌉=16−10=6;
- a3…a6:(15−3+4+8)−k⌈34⌉=24−20=4;
- a3…a7:(15−3+4+8+3)−k⌈35⌉=27−20=7。
你的任务是求出数组 a 的某个子数组(可以为空)的最大代价。
输入格式
The first line contains three integers n, m, and k (1≤n≤3⋅105,1≤m≤10,1≤k≤109).
The second line contains n integers a1,a2,…,an (−109≤ai≤109).
第一行包含三个整数 n、m 和 k(1≤n≤3⋅105,1≤m≤10,1≤k≤109)。
第二行包含 n 个整数 a1,a2,…,an(−109≤ai≤109)。
输出格式
Print the maximum cost of some subarray of array a.
输出数组 a 的某个子数组的最大代价。
输入输出样例
输入#1
7 3 10 2 -4 15 -3 4 8 3
输出#1
7
输入#2
5 2 1000 -13 -4 -9 -20 -11
输出#2
0
输入解题思路,AI测评打分。不知道怎么写?