@[Ellen7ions](/space/show?uid=51180) 可以的。
by ⚡GG⚡ @ 2018-05-07 21:45:20
我和你的思路一样,但我过了样例,原因应该是最后几个数的和恰好等于M时答案不需要加一。这是代码
```cpp
#include <bits/stdc++.h>
using namespace std;
int num[100001];
int main()
{
int N, M, sum = 0, tot = 0;
scanf ("%d%d", &N, &M);
for (int i = 1; i <= N; i++)
{
scanf ("%d", &num[i]);
sum += num[i];
if (sum > M)
{
sum = num[i];
tot++;
}
else if (sum == M)
{
sum = 0;
tot++;
}
}
if (sum == 0)
printf ("%d", tot);
else
printf ("%d", tot + 1);
return 0;
}
```
by 祥瑞御免 @ 2018-07-30 19:38:52