Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- using namespace std;
- int main() {
- int n;
- long long k;
- cin >> n >> k;
- vector<int> a(n);
- for (int i = 0; i < n; i++)
- cin >> a[i];
- queue<int> q;
- long long currentSum = 0;
- int maxLength = 0;
- for (int i = 0; i < n; ++i) {
- q.push(a[i]);
- currentSum += a[i];
- while (currentSum > k) {
- currentSum -= q.front();
- q.pop();
- }
- maxLength = max(maxLength, (int)q.size());
- }
- cout << maxLength << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement