Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- 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;
- int sum = 0;
- int rezultat = 0;
- for(int i = 0; i < n; i++) {
- while(j < n and sum + niza[j] <= M) {
- sum += niza[j];
- j++;
- }
- if(rezultat < j - i) {
- rezultat = j - i;
- }
- sum -= niza[i];
- }
- cout << rezultat << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement