输入描述:
第一行数据三个整数:n,t,c(1≤n≤2e5,0≤t≤1e9,1≤c≤n),第二行按入狱时间给出每个犯人的罪行值ai(0≤ai≤1e9)
输出描述:
一行输出答案。
输入例子:
3 100 2 1 2 3
输出例子:
2
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int n = in.nextInt();// n个人
int t = in.nextInt();//
int c = in.nextInt();// 连续c名
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
int count = 0;
int tempt = 0;
for (int i = 0; i < c; i++) {
tempt += a[i];//先计算前c个.比如:1 ,2;
}
if (tempt <= t)
count++;
for (int i = c; i < a.length; i++) {
tempt = tempt + a[i] - a[i - c];
//减去最前面一个,加上后面一个,就是后c个的和了。比如1,2,3,减去1的,加上3的就是2和3的和了
if (tempt <= t)
count++;
}
System.out.println(count);
}
}
}