Advertisement
Josif_tepe

Untitled

Jun 2nd, 2021
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int n, m;
  10.     cin >> n >> m;
  11.     int niza[n];
  12.     for(int i = 0; i < n; i++) {
  13.         cin >> niza[i];
  14.     }
  15.     int j = 0;
  16.     int sum = 0;
  17.     int rezult = 0;
  18.     for(int i = 0; i < n; i++) {
  19.         while(j < n and sum + niza[j] <= m) {
  20.             if(rezult < j - i + 1) {
  21.                 rezult = j - i + 1;
  22.             }
  23.             sum += niza[j];
  24.             j++;
  25.         }
  26.         sum -= niza[i];
  27.     }
  28.     cout << rezult << endl;
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement