Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int prefix_sum[100001];
- int suma(int i, int j) {
- if(i == 0) {
- return prefix_sum[j];
- }
- return prefix_sum[j] - prefix_sum[i - 1];
- }
- int main()
- {
- int n, m;
- cin >> n >> m;
- int niza[n];
- int sum = 0;
- for(int i = 0; i < n; i++) {
- cin >> niza[i];
- sum += niza[i];
- prefix_sum[i] = sum;
- }
- int rezult = 0;
- for(int i = 0; i < n; i++) {
- int S = i + 1;
- int E = n - 1;
- while(S <= E) {
- int middle = (S + E) / 2;
- sum = suma(i, middle);
- if(sum <= m) {
- if(rezult < middle - i + 1) {
- rezult = middle - i + 1;
- }
- S = middle + 1;
- }
- else {
- E = middle - 1;
- }
- }
- }
- cout << rezult << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement