Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n, m;
- cin >> n >> m;
- int niza[n];
- int pref_sums[n];
- int sum = 0;
- for(int i = 0; i < n; i++) {
- cin >> niza[i];
- sum += niza[i];
- pref_sums[i] = sum;
- }
- int res = 0;
- for(int i = 0; i < n; i++) {
- int L = i + 1;
- int R = n - 1;
- while(L <= R) {
- int middle = (L + R) / 2;
- if(i == 0) {
- sum = pref_sums[middle];
- }
- else {
- sum = pref_sums[middle] - pref_sums[i - 1];
- }
- if(sum <= m) {
- res = max(res, middle - i + 1);
- L = middle + 1;
- }
- else {
- R = middle - 1;
- }
- }
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement