Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <map>
- #include <set>
- using namespace std;
- typedef long long ll;
- vector<ll> v, pref_sum;
- ll sum(int L, int R) {
- if(L - 1 < 0) {
- return pref_sum[R];
- }
- return pref_sum[R] - pref_sum[L - 1];
- }
- int main() {
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- ll M;
- cin >> M;
- ll s = 0;
- for(int i =0 ; i < n; ++i) {
- ll x;
- cin >> x;
- v.push_back(x);
- s += x;
- pref_sum.push_back(s);
- }
- int ret = 0;
- for(int i = 0; i < n; ++i) {
- int L = i + 1;
- int R = n - 1;
- while(L <= R) {
- int mid = (L + R) / 2;
- if(sum(i, mid) <= M) {
- ret = max(ret, mid - i + 1);
- L = mid + 1;
- }
- else {
- R = mid - 1;
- }
- }
- }
- cout << ret << endl;
- return 0;
- }
- /*
- 8
- 1 2 1 3 2 7 4 2 1 2 3 4 5 6 7 8
- */
Advertisement
Add Comment
Please, Sign In to add comment