Advertisement
vlatkovski

Zhicarnica (Zicarnica)

Oct 5th, 2017
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int n, m; cin >> n >> m;
  6.     vector<int> v(n);
  7.     for (int i = 0; i < n; ++i) {
  8.         cin >> v[i];
  9.     }
  10.     int cnt = 1;
  11.     int r = m;
  12.     while (!v.empty()) {
  13.         int a = v[0];
  14.         if (a > r || r <= 0) {
  15.             r = m;
  16.             cnt++;
  17.         }
  18.         if (a <= r) {
  19.             r -= a;
  20.             v.erase(v.begin());
  21.         }
  22.     }
  23.     cout << cnt << endl;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement