错误示范:运行超时,只通过90%;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int n = in.nextInt();
int t = in.nextInt();
int c = in.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = in.nextInt();
}
int left = 0, right = left + c - 1;
long res = 0;
long temp = 0;
while (right < n) {
//虽然是滑动窗口,但是每次滑动都是重新计算窗口内的犯罪值
for (int i = left; i <= right; i++) {
temp += arr[i];
}
if (temp <= t) res++;
right++;
left++;
temp = 0;
}
System.out.println(res);
}
}
}