Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <stdio.h>
- #include <memory.h>
- #include <algorithm>
- #include <vector>
- #include <cmath>
- using namespace std;
- #define mp make_pair
- #define pb push_back
- #define _(a,b) memset( (a), b, sizeof( a ) )
- #define all(a) a.begin(), a.end()
- #define sz(a) (int)a.size()
- #define foreach(struct, iterator) for (iterator=struct.begin(); iterator != struct.end(); ++iterator)
- #define forn(i, n) for (i=0; i < n; i++)
- #define forab(i, a, b) for (i=a; i < b; i++)
- void prepare(string s)
- {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- #else
- if (sz(s) != 0)
- {
- freopen((s + ".in").c_str(),"r",stdin);
- freopen((s + ".out").c_str(),"w",stdout);
- }
- #endif
- }
- int seq[100000];
- vector <int> ss;
- vector <int> chsum(int x, int n)
- {
- int i;
- vector <int> s;
- s.pb(seq[0]);
- forab(i, 1, x) s[0]+=seq[i];
- forab(i, x, n) s.pb(s.back()-seq[i-x]+seq[i]);
- return s;
- }
- int main()
- {
- int n, s;
- bool f;
- prepare("");
- while (cin >> n)
- {
- int i, k, l, r, x;
- cin >> s;
- forn(i, n) cin >> seq[i];
- l=1;
- r=n;
- while (l < r)
- {
- x=(l+r)/2;
- ss=chsum(x, n);
- k=*max_element(all(ss));
- f=(k < s);
- if (f) l=x+1;
- else r=x;
- }
- cout << l << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement