Advertisement
Josif_tepe

Untitled

Mar 19th, 2021
89
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 <queue>
  3. #include <algorithm>
  4. #include <map>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int n, x;
  10.     cin >> n >> x;
  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 maks = 0;
  18.     for(int i = 0; i < n; i++) {
  19.         while(j < n and sum + niza[j] <= x) {
  20.             sum += niza[j];
  21.             j++;
  22.             maks = max(maks, j - i);
  23.         }
  24.         sum -= niza[i];
  25.     }
  26.     cout << maks << endl;
  27.     return 0;
  28. }
  29.  
  30. /*
  31.  6 55
  32.  12 |13 14 12 11 11|
  33.  
  34.  */
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement