Advertisement
Josif_tepe

Untitled

Mar 29th, 2021
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include<algorithm>
  3. #include<math.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n,m;
  9.     cin>>n>>m;
  10.     int s[n];
  11.     for(int i=0; i<n; i++)
  12.     {
  13.         cin>>s[i];
  14.     }
  15.     int zbir=0;
  16.     int brojac=0;
  17.     for(int i=0; i<n;)
  18.     {
  19.         while(zbir+s[i]<=m && i<n)
  20.         {
  21.             zbir+=s[i];
  22.             i++;
  23.         }
  24.         brojac++;
  25.         zbir=0;
  26.     }
  27.     cout<<brojac;
  28.     return 0;
  29. }
  30. // 2 3 2 1
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement