题目链接:http://118.190.20.162/view.page?gpid=T57
最后一块重量大于0就得加1
1 #include <iostream> 2 #include <algorithm> 3 #include <cmath> 4 #include <string> 5 #include <cstring> 6 using namespace std; 7 int n,k; 8 int a[1005]; 9 int main() 10 { 11 while(cin>>n>>k){ 12 int t=0,sum=0; 13 for(int i=0;i<n;i++){ 14 cin>>a[i]; 15 sum+=a[i]; 16 if(sum>=k){ 17 t++; 18 //cout<<sum<<endl; 19 sum=0; 20 } 21 } 22 cout<<t+(sum>0)<<endl; 23 } 24 return 0; 25 }