Advertisement
Josif_tepe

Untitled

Apr 12th, 2021
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4.     int n, m;
  5.     cin >> n >> m;
  6.     int a[100005];
  7.     int s = 0;
  8.     for(int i = 0; i < n; i++) {
  9.         cin >> a[i];
  10.     }
  11.     int j = 0, ret = 0;
  12.     for(int i = 0; i < n; i++) {
  13.         while(j < n and s + a[j] <= m) {
  14.             ret = max(ret, j - i + 1);
  15.             s += a[j];
  16.             j++;
  17.         }
  18.         s -= a[i];
  19.     }
  20.     cout << ret << endl;
  21.     return 0;
  22. }
  23. // 1 2 3 4 5
  24. // a --> b imame tocno b - a + 1
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement