Advertisement
Josif_tepe

Untitled

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