题解 | #罪犯转移#

罪犯转移

http://www.nowcoder.com/practice/b7b1ad820f0a493aa128ed6c9e0af448

错误示范:运行超时,只通过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);
        }
    }
}
全部评论

相关推荐

数开小菜鸡:你是我今早见过的最美的牛客女孩......
点赞 评论 收藏
分享
MingoTree:看不出你你的技术栈,想找什么工作,然后课设项目别写上去了,自我评价删了,前后端你想好你要干啥,这种简历投上去秒挂的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务