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;
- int main() {
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- ll M;
- cin >> M;
- vector<ll> v(n);
- for(int i =0 ; i < n; ++i) {
- cin >> v[i];
- }
- ll sum = 0;
- int ret = 0
- ;
- int j = 0;
- for(int i = 0; i < n; ++i) {
- while(j < n and sum + v[j] <= M) {
- sum += v[j];
- ++j;
- ret = max(ret, j - i);
- }
- sum -= v[i];
- ret = max(ret, j - i);
- }
- 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