CF1057B DDoS 题解
Content
有一个长度为 \(n\) 的数列 \(a_1,a_2,...,a_n\),求出满足 \(\sum\limits_{i=l}^r a_i>100\times(r-l+1)\) 的区间 \([l,r]\) 长度的最大值。
数据范围:\(1\leqslant n\leqslant 5000,0\leqslant a_i\leqslant 5000\)。
Solution
前缀和简单题,我们预处理出所有的前缀和之后,再直接 \(\mathcal{O}(n^2)\) 枚举所有满足条件的区间长度,取其最大值即可。
Code
int n, r, s[5007], ans;
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {scanf("%d", &r); s[i] = s[i - 1] + r;}
for(int i = 1; i <= n; ++i)
for(int j = i; j <= n; ++j)
if(s[j] - s[i - 1] > 100 * (j - i + 1)) ans = max(ans, j - i + 1);
printf("%d", ans);
return 0;
}