Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define f first
- #define s second
- #define pb push_back
- #define mp make_pair
- #define ll long long
- #define IOS ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
- using namespace std;
- const int INF = 1e9 + 1;
- const int MOD = 1e9 + 7;
- const int MOD2 = 1e9 + 9;
- const int MAXN = 1e5 + 10;
- void solve(){
- int n;
- ll s;
- cin >> n >> s;
- int a[n + 1];
- for (int i = 1; i <= n; i++){
- cin >> a[i];
- }
- int right = 0;
- ll sum = 0;
- int ans = 0;
- for (int left = 1; left <= n; left++){
- while(right < n && sum <= s){
- right++;
- sum += a[right];
- }
- if (sum > s){
- ans = max(ans, right - left);
- }
- else{
- ans = max(ans, right - left + 1);
- }
- sum -= a[left];
- }
- cout << ans;
- }
- int main() {
- IOS;
- int t = 1;
- //cin >> t;
- while(t--){
- solve();
- }
- return 0;
- }
Advertisement