Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #include <map>
- using namespace std;
- int main() {
- int n, m;
- cin >> n >> m;
- int niza[n];
- for(int i = 0; i < n; i++) {
- cin >> niza[i];
- }
- int j = 0, sum = 0;
- int res = 0;
- for(int i = 0; i < n; i++) {
- while(j < n and sum + niza[j] <= m) {
- sum += niza[j];
- j++;
- res = max(res, j - i);
- }
- sum -= niza[i];
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement