使用动态规划,求前i项犯罪值之和sum,然后然后判断是否是c名罪犯。

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            int t = sc.nextInt();
            int c = sc.nextInt();
            int[] nums = new int[n];
            for(int i = 0;i<n;i++){
                nums[i] = sc.nextInt();
            }
            int res = 0;
            int sum = nums[0];
            int start =0;
            for(int i = 1;i<n;i++){
                sum +=nums[i];
                while(sum>t){
                    sum-=nums[start++];
                }
                if(i-start+1== c){
                    res++;
                    sum-=nums[start++];
                }
            }
            System.out.println(res);
        }
    }
}