Advertisement
Josif_tepe

Untitled

Mar 19th, 2024
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <queue>
  5. #include <cstring>
  6. using namespace std;
  7.  
  8. typedef long long ll;
  9. int main() {
  10.     ios_base::sync_with_stdio(false);
  11.     int n, m;
  12.     cin >> n >> m;
  13.     vector<int> v(n);
  14.    
  15.     for(int i = 0; i < n; i++) {
  16.         cin >> v[i];
  17.     }
  18.    
  19.     int R = 0;
  20.     int sum = 0;
  21.     int res = 0;
  22.     for(int L = 0; L < n; L++) {
  23.         while(R < n and sum + v[R] <= m) {
  24.             sum += v[R];
  25.             R++;
  26.         }
  27.         res = max(res, R - L);
  28.         sum -= v[L];
  29.     }
  30.    
  31.     cout << res << endl;
  32.     return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement