Advertisement
7oSkaaa

Books

Aug 11th, 2021
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1.   #include <bits/stdc++.h>
  2.   using namespace std;
  3.  
  4.   #define cin(vec) for(auto& i : vec) cin >> i
  5.   #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++);
  6.   #define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n";
  7.   #define cout_2d(vec, n, m) for(int i = 0; i < n; i++, cout << "\n") for(int j = 0; j < m && cout << vec[i][j] << " "; j++);
  8.   #define cout_map(mp) for(auto& [f, s] : mp) cout << f << "  " << s << "\n";
  9.   #define fixed(n) cout << fixed << setprecision(n);
  10.   #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  11.   #define Fill(vec, value) memset(vec, value, sizeof(vec));
  12.   #define Num_of_Digits(n) ((int)log10(n)+1)
  13.   #define all(vec) vec.begin(),vec.end()
  14.   #define rall(vec) vec.rbegin(),vec.rend()
  15.   #define sz(x) int(x.size())
  16.   #define fi first
  17.   #define se second
  18.   #define Pair pair < int, int >
  19.   #define ll long long
  20.   #define ull unsigned long long
  21.   #define Mod  1'000'000'007
  22.   #define INF 2'000'000'000
  23.   #define PI acos(-1)
  24.  
  25.   void Code_Crush(){
  26.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  27.     #ifndef ONLINE_JUDGE
  28.       freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  29.     #endif
  30.   }
  31.  
  32.   int main(){
  33.       Code_Crush();
  34.       int n, t;                                           cin >> n >> t;
  35.       vector < ll > books(n + 1);
  36.       for(int i = 1, entry; i <= n && cin >> entry; i++) books[i] = entry + books[i - 1];
  37.       int l = 1, r = 1, Max = -INF;
  38.       while(r <= n){
  39.         while(books[r] - books[l - 1] > t) l++;
  40.         Max = max(Max, r - l + 1);
  41.         r++;
  42.       }
  43.       cout << Max;
  44.       return 0;
  45.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement