Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- const int maxn = 2e5 + 10;
- typedef long long ll;
- ll pref_sum[maxn];
- ll query(int i, int j) {
- if(i == 0) {
- return pref_sum[j];
- }
- return pref_sum[j] - pref_sum[i - 1];
- }
- int main() {
- ios_base::sync_with_stdio(false);
- int n;
- ll m;
- cin >> n >> m;
- vector<ll> v(n);
- ll sum = 0;
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- sum += v[i];
- pref_sum[i] = sum;
- }
- int res = 0;
- for(int i = 0; i < n; i++) {
- int L = i, R = n - 1;
- int j = 0;
- while(L <= R) {
- int mid = (L + R) / 2;
- if(query(i, mid) <= m) {
- L = mid + 1;
- j = max(j, mid);
- }
- else {
- R = mid - 1;
- }
- }
- res = max(res, j - i + 1);
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement