淘先锋技术网
首页
1
2
3
4
5
6
7
ccf 201703-1分蛋糕
package com.sep.fourteenth; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int[] cake=new int[n]; for (int i = 0; i < n; i++) { cake[i]=sc.nextInt(); } int count=0; int i=0; int out; while (i<n){ out=cake[i]; for(;out<k&&i<=n-2;i++){ out=out+cake[i+1]; } count++; i++; } System.out.print(count); sc.close(); } }