标签:cti const ret pen clu eve namespace ref lse
https://www.luogu.com.cn/problem/P1181
模拟一下这个过程
从第一个数开始,如果符合条件.res += a[i];
不符合的话,ans++;res = 0,res += a[i];
#include<bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int a[maxn]; int n, m; int ans = 1; int main() { ios::sync_with_stdio(0); cin >> n >> m; int res = 0; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (res + a[i] > m) { ans++; res = 0; } res += a[i]; } cout << ans; return 0; }
标签:cti const ret pen clu eve namespace ref lse
原文地址:https://www.cnblogs.com/xcfxcf/p/12365861.html