Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<algorithm>
- #include<math.h>
- using namespace std;
- int main()
- {
- int n,m;
- cin>>n>>m;
- int s[n];
- for(int i=0; i<n; i++)
- {
- cin>>s[i];
- }
- int zbir=0;
- int brojac=0;
- for(int i=0; i<n;)
- {
- while(zbir+s[i]<=m && i<n)
- {
- zbir+=s[i];
- i++;
- }
- brojac++;
- zbir=0;
- }
- cout<<brojac;
- return 0;
- }
- // 2 3 2 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement