博客中的文章均为meelo原创,请务必以链接形式注明本文地址
#include <cstdio> int main() { int N, K; scanf("%d%d", &N, &K); int cnt = 0; int weight, total = 0; for(int n=0; n<N; n++) { scanf("%d", &weight); total += weight; if(total >= K) { cnt++; total = 0; } } if(total > 0) cnt++; printf("%d\n", cnt); }
原文:http://www.cnblogs.com/meelo/p/7636088.html