Advertisement
tepyotin2

Virus

May 1st, 2025
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     long long k;
  8.     cin >> n >> k;
  9.  
  10.     vector<int> a(n);
  11.     for (int i = 0; i < n; i++)
  12.         cin >> a[i];
  13.  
  14.     queue<int> q;
  15.     long long currentSum = 0;
  16.     int maxLength = 0;
  17.  
  18.     for (int i = 0; i < n; ++i) {
  19.         q.push(a[i]);
  20.         currentSum += a[i];
  21.  
  22.         while (currentSum > k) {
  23.             currentSum -= q.front();
  24.             q.pop();
  25.         }
  26.  
  27.         maxLength = max(maxLength, (int)q.size());
  28.     }
  29.  
  30.     cout << maxLength << endl;
  31.     return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement