链接P1181
感想
放在贪心的标题底下,就是最简单的使每一段最接近m就行,但是感觉不会这么简单?应该是数据太水了吧
code
#include <algorithm>
#include <stdio.h>
#include <iostream>
using namespace std;
const int maxn = 100000+5;
int a[maxn];
int main()
{
#ifdef LOCAL
freopen("C:\\Users\\hsxny\\Desktop\\in.txt", "r", stdin);
#endif
int n,m;
cin>>n>>m;
int sum=0;
int ans = 0;
for(int i=0;i<n;i++)
{
int now = 0;
scanf("%d",&a[i]);
now = a[i];
if(sum+now>m)
{
sum = now;
ans++;
}
else
{
sum+=now;
}
}
cout<<ans+1<<endl;
return 0;
}