josiftepe

Untitled

Oct 24th, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <map>
  5. #include <set>
  6. using namespace std;
  7. typedef long long ll;
  8. int main() {
  9.     ios_base::sync_with_stdio(false);
  10.     int n;
  11.     cin >> n;
  12.     ll M;
  13.     cin >> M;
  14.     vector<ll> v(n);
  15.     for(int i =0 ; i < n; ++i) {
  16.         cin >> v[i];
  17.     }
  18.     ll sum = 0;
  19.     int ret = 0
  20.     ;
  21.     int j = 0;
  22.     for(int i = 0; i < n; ++i) {
  23.         while(j < n and sum + v[j] <= M) {
  24.             sum += v[j];
  25.             ++j;
  26.             ret = max(ret, j - i);
  27.         }
  28.         sum -= v[i];
  29.         ret = max(ret, j - i);
  30.     }
  31.     cout << ret << endl;
  32.     return 0;
  33. }
  34.  
  35.  
  36.  
  37.  
  38.  
  39. /*
  40.  8
  41.  1 2 1 3 2 7 4 2 1 2 3 4 5 6 7 8
  42.  */
  43.  
Advertisement
Add Comment
Please, Sign In to add comment