题目分析:
Code:
#include <bits/stdc++.h>
using namespace std;
#define maxn 100010
int n,a[maxn],m;
inline int read_() {
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9') {
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9') {
x=(x<<1)+(x<<3)+c-'0';
c=getchar();
}
return x*f;
}
void readda_() {
n=read_();m=read_();
for(int i=1;i<=n;++i) {
a[i]=read_();
}
int sum=a[1],cnt=1;
for(int i=2;i<=n;++i) {
if( (sum+a[i])<=m ) sum+=a[i];
else {
++cnt;
sum=a[i];
}
}
printf("%d",cnt);
}
int main() {
freopen("a.txt","r",stdin);
readda_();
return 0;
}