没发现可以这么做吗?
```#include<iostream>
using namespace std;
int main()
{
int n,s;
cin>>n>>s;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
int ans=0;
int t=s;
for(int i=0;i<n;i++)
{
if(a[i]>t){
ans++;
t=s-a[i];
}
else
t-=a[i];
}
cout<<ans+1;
return 0;
}
```
by Wiene @ 2018-11-05 10:59:50
@[Msaikoto](/space/show?uid=100331) 最后还要判断一下,如果最后一段不超过m,直接输出,否则还要加一。
total应该等于0。
by Wiene @ 2018-11-05 11:07:25
@[AC鸭](/space/show?uid=116689) 了解了!谢谢!
by Msaikoto @ 2018-11-05 13:17:33
```
#include<iostream>
using namespace std;
int n,m,l,r,mid,tot,tim,a[100005];
bool check(int x) {
for(int i=1; i<=n; i++)
if(tot+a[i]<=x)
tot+=a[i];
else {
tot=a[i];
tim++;
}
return tim>=m;
}
int main() {
cin>>n>>m;
for(int i=1; i<=n; i++) {
cin>>a[i];
r+=a[i];
l=max(l,a[i]);
}
while(l<=r) {
mid=(l+r)/2;
tot=0,tim=0;
if(check(mid))
l=mid+1;
else
r=mid-1;
}
cout<<l;
return 0;
}
```
by Del_Your_Heart @ 2018-12-08 16:46:13
@[AC鸭](/space/show?uid=116689) 我11月就AC了~~个头,根本就没在意这个题太简单了~~
by Chara·Fun·Foxy @ 2019-01-25 21:27:19
```cpp
#include<iostream>
using namespace std;
int a[100005];
int ans,tmp;
int main(){
int n,m;
cin>>n>>m;
for(int i = 0;i<n;i++){
cin>>a[i];
tmp+=a[i];
if(tmp>m){
ans++;
tmp = a[i];
}
}
cout<<ans+1;
return 0;
}
```
by Computer1828 @ 2019-05-01 15:51:05