Advertisement
Josif_tepe

Untitled

Jan 27th, 2024
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n, k;
  8.     cin >> n >> k;
  9.     int niza[n];
  10.    
  11.     for(int i = 0; i < n; i++) {
  12.         cin >> niza[i];
  13.     }
  14.     int zbir_na_lugje = 0;
  15.     int gondoli = 1;
  16.     for(int i = 0; i < n; i++) {
  17.         if(zbir_na_lugje + niza[i] <= k) {
  18.             zbir_na_lugje += niza[i];
  19.         }
  20.         else {
  21.             zbir_na_lugje = niza[i];
  22.             gondoli += 1;
  23.         }
  24.     }
  25.     cout << gondoli << endl;
  26.     return 0;
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement